Class: Tenacity::AssociatesProxy
- Inherits:
-
Object
- Object
- Tenacity::AssociatesProxy
show all
- Defined in:
- lib/tenacity/associates_proxy.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(parent, target, association) ⇒ AssociatesProxy
Returns a new instance of AssociatesProxy.
6
7
8
9
10
|
# File 'lib/tenacity/associates_proxy.rb', line 6
def initialize(parent, target, association)
@parent = parent
@target = target
@association = association
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/tenacity/associates_proxy.rb', line 78
def method_missing(method, *args)
if block_given?
@target.send(method, *args) { |*block_args| yield(*block_args) }
else
@target.send(method, *args)
end
end
|
Instance Method Details
#<<(object) ⇒ Object
21
22
23
24
25
|
# File 'lib/tenacity/associates_proxy.rb', line 21
def <<(object)
object._t_save_if_dirty unless @parent.id.nil?
@target << AssociateProxy.new(object, @association)
mark_parent_dirty
end
|
#===(other) ⇒ Object
Explicitly proxy === because the instance method removal above doesn’t catch it.
17
18
19
|
# File 'lib/tenacity/associates_proxy.rb', line 17
def ===(other)
other === @target
end
|
#clear(*args) ⇒ Object
62
63
64
65
|
# File 'lib/tenacity/associates_proxy.rb', line 62
def clear(*args)
mark_parent_dirty
@target.clear(*args)
end
|
#concat(objects) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/tenacity/associates_proxy.rb', line 34
def concat(objects)
objects.each { |object| object._t_save_if_dirty } unless @parent.id.nil?
proxies = objects.map { |object| AssociateProxy.new(object, @association) }
@target.concat(proxies)
mark_parent_dirty
end
|
#delete(*args) ⇒ Object
57
58
59
60
|
# File 'lib/tenacity/associates_proxy.rb', line 57
def delete(*args)
mark_parent_dirty
@target.delete(*args)
end
|
#delete_all ⇒ Object
47
48
49
50
51
|
# File 'lib/tenacity/associates_proxy.rb', line 47
def delete_all
remove_associates_from_parent
@association.associate_class._t_delete(@parent._t_get_associate_ids(@association), false)
mark_parent_dirty
end
|
#destroy_all ⇒ Object
41
42
43
44
45
|
# File 'lib/tenacity/associates_proxy.rb', line 41
def destroy_all
remove_associates_from_parent
@association.associate_class._t_delete(@parent._t_get_associate_ids(@association))
mark_parent_dirty
end
|
#inspect ⇒ Object
53
54
55
|
# File 'lib/tenacity/associates_proxy.rb', line 53
def inspect
@target.inspect
end
|
#proxy_respond_to? ⇒ Object
3
|
# File 'lib/tenacity/associates_proxy.rb', line 3
alias_method :proxy_respond_to?, :respond_to?
|
#push(*objects) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/tenacity/associates_proxy.rb', line 27
def push(*objects)
objects.each { |object| object._t_save_if_dirty } unless @parent.id.nil?
proxies = objects.map { |object| AssociateProxy.new(object, @association) }
@target.push(*proxies)
mark_parent_dirty
end
|
#respond_to?(*args) ⇒ Boolean
12
13
14
|
# File 'lib/tenacity/associates_proxy.rb', line 12
def respond_to?(*args)
proxy_respond_to?(*args) || @target.respond_to?(*args)
end
|