Class: MongoMapper::Plugins::Associations::Proxy
- Inherits:
-
Object
- Object
- MongoMapper::Plugins::Associations::Proxy
show all
- Defined in:
- lib/novelys_mongo_mapper/plugins/associations/proxy.rb
Instance Attribute Summary collapse
-
#owner ⇒ Object
(also: #proxy_owner)
readonly
Returns the value of attribute owner.
-
#reflection ⇒ Object
(also: #proxy_reflection)
readonly
Returns the value of attribute reflection.
-
#target ⇒ Object
(also: #proxy_target)
readonly
Returns the value of attribute target.
Instance Method Summary
collapse
Constructor Details
#initialize(owner, reflection) ⇒ Proxy
Returns a new instance of Proxy.
20
21
22
23
24
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 20
def initialize(owner, reflection)
@owner, @reflection, @loaded = owner, reflection, false
Array(reflection.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
88
89
90
91
92
93
94
95
96
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 88
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
#owner ⇒ Object
Also known as:
proxy_owner
Returns the value of attribute owner.
10
11
12
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 10
def owner
@owner
end
|
#reflection ⇒ Object
Also known as:
proxy_reflection
Returns the value of attribute reflection.
10
11
12
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 10
def reflection
@reflection
end
|
#target ⇒ Object
Also known as:
proxy_target
Returns the value of attribute target.
10
11
12
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 10
def target
@target
end
|
Instance Method Details
#===(other) ⇒ Object
82
83
84
85
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 82
def ===(other)
load_target
other === target
end
|
44
45
46
47
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 44
def blank?
load_target
target.blank?
end
|
26
27
28
29
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 26
def inspect
load_target
target.inspect
end
|
35
36
37
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 35
def loaded
@loaded = true
end
|
31
32
33
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 31
def loaded?
@loaded
end
|
39
40
41
42
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 39
def nil?
load_target
target.nil?
end
|
49
50
51
52
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 49
def present?
load_target
target.present?
end
|
#proxy_respond_to? ⇒ Object
5
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 5
alias :proxy_respond_to? :respond_to?
|
54
55
56
57
58
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 54
def reload
reset
load_target
self unless target.nil?
end
|
#replace(v) ⇒ Object
60
61
62
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 60
def replace(v)
raise NotImplementedError
end
|
64
65
66
67
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 64
def reset
@loaded = false
@target = nil
end
|
#respond_to?(*args) ⇒ Boolean
69
70
71
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 69
def respond_to?(*args)
proxy_respond_to?(*args) || (load_target && target.respond_to?(*args))
end
|
#send(method, *args) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/novelys_mongo_mapper/plugins/associations/proxy.rb', line 73
def send(method, *args)
if proxy_respond_to?(method)
super
else
load_target
target.send(method, *args)
end
end
|