Class: NinjaModel::Associations::CollectionProxy
- Inherits:
-
Object
- Object
- NinjaModel::Associations::CollectionProxy
show all
- Defined in:
- lib/ninja_model/associations/collection_proxy.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of CollectionProxy.
12
13
14
|
# File 'lib/ninja_model/associations/collection_proxy.rb', line 12
def initialize(association)
@association = association
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/ninja_model/associations/collection_proxy.rb', line 26
def method_missing(method, *args, &block)
if target.respond_to?(method) || (!proxy_association.klass.respond_to?(method) && Class.respond_to?(method))
if load_target
if target.respond_to?(method)
target.send(method, *args, &block)
else
begin
super
rescue NoMethodError => e
raise e, e.message.sub(/ for #<.*$/, "via proxy for #{target}")
end
end
end
else
scoped.send(method, *args, &block)
end
end
|
Instance Method Details
#proxy_association ⇒ Object
16
17
18
|
# File 'lib/ninja_model/associations/collection_proxy.rb', line 16
def proxy_association
@association
end
|
#respond_to?(name, include_private = false) ⇒ Boolean
20
21
22
23
24
|
# File 'lib/ninja_model/associations/collection_proxy.rb', line 20
def respond_to?(name, include_private = false)
super ||
(load_target && target.respond_to?(name, include_private)) ||
proxy_association.klass.respond_to?(name, include_private)
end
|