Class: MongoMapper::Associations::Proxy
- Inherits:
-
BasicObject
- Defined in:
- lib/mongo_mapper/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
11
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 6
def initialize(owner, association)
@owner = owner
@association = association
@association.options[:extend].each { |ext| proxy_extend(ext) }
reset
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 48
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/mongo_mapper/associations/proxy.rb', line 4
def association
@association
end
|
Returns the value of attribute owner.
4
5
6
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 4
def owner
@owner
end
|
Instance Method Details
37
38
39
40
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 37
def inspect
load_target
@target.inspect
end
|
42
43
44
45
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 42
def nil?
load_target
@target.nil?
end
|
#reload_target ⇒ Object
21
22
23
24
25
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 21
def reload_target
reset
load_target
self
end
|
#replace(v) ⇒ Object
33
34
35
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 33
def replace(v)
raise NotImplementedError
end
|
17
18
19
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 17
def reset
@target = nil
end
|
#respond_to?(*methods) ⇒ Boolean
13
14
15
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 13
def respond_to?(*methods)
(load_target && @target.respond_to?(*methods))
end
|
#send(method, *args) ⇒ Object
27
28
29
30
31
|
# File 'lib/mongo_mapper/associations/proxy.rb', line 27
def send(method, *args)
return super if methods.include?(method.to_s)
load_target
@target.send(method, *args)
end
|