Class: MongoMapper::Associations::Proxy
- Inherits:
-
BasicObject
- 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.
6
7
8
9
10
|
# File 'lib/mongomapper/associations/proxy.rb', line 6
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
47
48
49
50
51
52
53
54
55
|
# File 'lib/mongomapper/associations/proxy.rb', line 47
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
|
Returns the value of attribute owner.
4
5
6
|
# File 'lib/mongomapper/associations/proxy.rb', line 4
def owner
@owner
end
|
Instance Method Details
36
37
38
39
|
# File 'lib/mongomapper/associations/proxy.rb', line 36
def inspect
load_target
@target.inspect
end
|
41
42
43
44
|
# File 'lib/mongomapper/associations/proxy.rb', line 41
def nil?
load_target
@target.nil?
end
|
#reload_target ⇒ Object
20
21
22
23
24
|
# File 'lib/mongomapper/associations/proxy.rb', line 20
def reload_target
reset
load_target
self
end
|
#replace(v) ⇒ Object
32
33
34
|
# File 'lib/mongomapper/associations/proxy.rb', line 32
def replace(v)
raise NotImplementedError
end
|
16
17
18
|
# File 'lib/mongomapper/associations/proxy.rb', line 16
def reset
@target = nil
end
|
#respond_to?(*methods) ⇒ Boolean
12
13
14
|
# File 'lib/mongomapper/associations/proxy.rb', line 12
def respond_to?(*methods)
(load_target && @target.respond_to?(*methods))
end
|
#send(method, *args) ⇒ Object
26
27
28
29
30
|
# File 'lib/mongomapper/associations/proxy.rb', line 26
def send(method, *args)
return super if methods.include? method.to_s
load_target
@target.send(method, *args)
end
|