Class: MongoMapper::Plugins::Associations::Proxy
- Inherits:
-
Object
- Object
- MongoMapper::Plugins::Associations::Proxy
show all
- Defined in:
- lib/mongo_mapper/plugins/associations/proxy.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
(also: #proxy_association)
readonly
Returns the value of attribute association.
-
#owner ⇒ Object
(also: #proxy_owner)
readonly
Returns the value of attribute owner.
-
#target ⇒ Object
(also: #proxy_target)
readonly
Returns the value of attribute target.
Instance Method Summary
collapse
Constructor Details
#initialize(owner, association) ⇒ Proxy
Returns a new instance of Proxy.
21
22
23
24
25
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 21
def initialize(owner, association)
@owner, @association, @loaded = owner, association, false
Array(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, &block) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 89
def method_missing(method, *args, &block)
if load_target
if block_given?
target.send(method, *args) { |*block_args| block.call(*block_args) }
else
target.send(method, *args)
end
end
end
|
Instance Attribute Details
#association ⇒ Object
Also known as:
proxy_association
Returns the value of attribute association.
11
12
13
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 11
def association
@association
end
|
#owner ⇒ Object
Also known as:
proxy_owner
Returns the value of attribute owner.
11
12
13
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 11
def owner
@owner
end
|
#target ⇒ Object
Also known as:
proxy_target
Returns the value of attribute target.
11
12
13
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 11
def target
@target
end
|
Instance Method Details
#===(other) ⇒ Object
83
84
85
86
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 83
def ===(other)
load_target
other === target
end
|
45
46
47
48
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 45
def blank?
load_target
target.blank?
end
|
27
28
29
30
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 27
def inspect
load_target
target.inspect
end
|
36
37
38
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 36
def loaded
@loaded = true
end
|
32
33
34
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 32
def loaded?
@loaded
end
|
40
41
42
43
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 40
def nil?
load_target
target.nil?
end
|
50
51
52
53
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 50
def present?
load_target
target.present?
end
|
#proxy_respond_to? ⇒ Object
6
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 6
alias :proxy_respond_to? :respond_to?
|
55
56
57
58
59
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 55
def reload
reset
load_target
self unless target.nil?
end
|
#replace(v) ⇒ Object
61
62
63
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 61
def replace(v)
raise NotImplementedError
end
|
65
66
67
68
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 65
def reset
@loaded = false
@target = nil
end
|
#respond_to?(*args) ⇒ Boolean
70
71
72
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 70
def respond_to?(*args)
proxy_respond_to?(*args) || (load_target && target.respond_to?(*args))
end
|
#send(method, *args) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/mongo_mapper/plugins/associations/proxy.rb', line 74
def send(method, *args)
if proxy_respond_to?(method)
super
else
load_target
target.send(method, *args)
end
end
|