Class: RailsAdmin::Config::LazyModel

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_admin/config/lazy_model.rb

Instance Method Summary collapse

Constructor Details

#initialize(entity, &block) ⇒ LazyModel


6
7
8
9
# File 'lib/rails_admin/config/lazy_model.rb', line 6

def initialize(entity, &block)
  @entity = entity
  @deferred_block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object


19
20
21
# File 'lib/rails_admin/config/lazy_model.rb', line 19

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

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean


23
24
25
# File 'lib/rails_admin/config/lazy_model.rb', line 23

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

#targetObject


11
12
13
14
15
16
17
# File 'lib/rails_admin/config/lazy_model.rb', line 11

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