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