Class: RailsAdmin::Config::LazyModel
- Inherits:
-
BasicObject
- Defined in:
- lib/rails_admin/config/lazy_model.rb
Instance Method Summary
collapse
Constructor Details
#initialize(entity, &block) ⇒ LazyModel
Returns a new instance of LazyModel.
6
7
8
9
10
|
# File 'lib/rails_admin/config/lazy_model.rb', line 6
def initialize(entity, &block)
@entity = entity
@deferred_blocks = [*block]
@existing_blocks = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
59
60
61
|
# File 'lib/rails_admin/config/lazy_model.rb', line 59
def method_missing(method_name, *args, &block)
target.send(method_name, *args, &block)
end
|
Instance Method Details
#add_deferred_block(&block) ⇒ Object
12
13
14
|
# File 'lib/rails_admin/config/lazy_model.rb', line 12
def add_deferred_block(&block)
@deferred_blocks << block
end
|
#respond_to?(method_name, include_private = false) ⇒ Boolean
63
64
65
|
# File 'lib/rails_admin/config/lazy_model.rb', line 63
def respond_to?(method_name, include_private = false)
super || target.respond_to?(method_name, include_private)
end
|
#target ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/rails_admin/config/lazy_model.rb', line 16
def target
@model ||= ::RailsAdmin::Config::Model.new(@entity)
unless @deferred_blocks.empty?
@existing_blocks += @deferred_blocks
@existing_blocks.
partition { |block| block.source_location.first =~ %r{config\/initializers} }.
flatten.
each { |block| @model.instance_eval(&block) }
@deferred_blocks = []
end
@model
end
|