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.
8
9
10
11
12
|
# File 'lib/rails_admin/config/lazy_model.rb', line 8
def initialize(entity, &block)
@entity = entity
@deferred_blocks = [*block]
@initialized = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
65
66
67
|
# File 'lib/rails_admin/config/lazy_model.rb', line 65
def method_missing(method_name, *args, &block)
target.send(method_name, *args, &block)
end
|
Instance Method Details
#add_deferred_block(&block) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/rails_admin/config/lazy_model.rb', line 14
def add_deferred_block(&block)
if @initialized
@model.instance_eval(&block)
else
@deferred_blocks << block
end
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
69
70
71
|
# File 'lib/rails_admin/config/lazy_model.rb', line 69
def respond_to_missing?(method_name, include_private = false)
super || target.respond_to?(method_name, include_private)
end
|
#target ⇒ Object
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
58
59
60
61
62
63
|
# File 'lib/rails_admin/config/lazy_model.rb', line 22
def target
@model ||= ::RailsAdmin::Config::Model.new(@entity)
unless @deferred_blocks.empty?
@deferred_blocks.
partition { |block| block.source_location.first =~ %r{config/initializers} }.
flatten.
each { |block| @model.instance_eval(&block) }
@deferred_blocks = []
end
@initialized = true
@model
end
|