Class: MongoMapper::Associations::Proxy
- Inherits:
-
Object
- Object
- MongoMapper::Associations::Proxy
show all
- Defined in:
- lib/mongomapper/associations/proxy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(owner, association) ⇒ Proxy
Returns a new instance of Proxy.
10
11
12
13
14
15
|
# File 'lib/mongomapper/associations/proxy.rb', line 10
def initialize(owner, association)
@owner= owner
@association = association
reset
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/mongomapper/associations/proxy.rb', line 41
def method_missing(method, *args)
if load_target
if block_given?
@target.send(method, *args) { |*block_args| yield(*block_args) }
else
@target.send(method, *args)
end
end
end
|
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
4
5
6
|
# File 'lib/mongomapper/associations/proxy.rb', line 4
def association
@association
end
|
#owner ⇒ Object
Returns the value of attribute owner.
4
5
6
|
# File 'lib/mongomapper/associations/proxy.rb', line 4
def owner
@owner
end
|
Instance Method Details
#reload_target ⇒ Object
25
26
27
28
29
|
# File 'lib/mongomapper/associations/proxy.rb', line 25
def reload_target
reset
load_target
self
end
|
#replace(v) ⇒ Object
36
37
38
|
# File 'lib/mongomapper/associations/proxy.rb', line 36
def replace(v)
raise NotImplementedError
end
|
#reset ⇒ Object
21
22
23
|
# File 'lib/mongomapper/associations/proxy.rb', line 21
def reset
@target = nil
end
|
#respond_to?(*methods) ⇒ Boolean
17
18
19
|
# File 'lib/mongomapper/associations/proxy.rb', line 17
def respond_to?(*methods)
(load_target && @target.respond_to?(*methods))
end
|
#send(method, *args) ⇒ Object
31
32
33
34
|
# File 'lib/mongomapper/associations/proxy.rb', line 31
def send(method, *args)
load_target
@target.send(method, *args)
end
|