File: lazy_model.rb

package info (click to toggle)
ruby-rails-admin 0.8.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,492 kB
  • ctags: 1,292
  • sloc: ruby: 5,341; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 660 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'rails_admin/config/model'

module RailsAdmin
  module Config
    class LazyModel < BasicObject
      def initialize(entity, &block)
        @entity = entity
        @deferred_block = block
      end

      def target
        unless @model
          @model = ::RailsAdmin::Config::Model.new(@entity)
          @model.instance_eval(&@deferred_block) if @deferred_block
        end
        @model
      end

      def method_missing(method, *args, &block)
        target.send(method, *args, &block)
      end

      def respond_to?(method, include_private = false)
        super || target.respond_to?(method, include_private)
      end
    end
  end
end