Class: ActiveRecord::Associations::AssociationProxy
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::AssociationProxy
show all
- Defined in:
- lib/active_record/associations/association_proxy.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(owner, reflection) ⇒ AssociationProxy
Returns a new instance of AssociationProxy.
10
11
12
13
14
|
# File 'lib/active_record/associations/association_proxy.rb', line 10
def initialize(owner, reflection)
@owner, @reflection = owner, reflection
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
123
124
125
126
127
|
# File 'lib/active_record/associations/association_proxy.rb', line 123
def method_missing(method, *args, &block)
if load_target
@target.send(method, *args, &block)
end
end
|
Instance Attribute Details
#reflection ⇒ Object
Returns the value of attribute reflection.
4
5
6
|
# File 'lib/active_record/associations/association_proxy.rb', line 4
def reflection
@reflection
end
|
Instance Method Details
#===(other) ⇒ Object
Explicitly proxy === because the instance method removal above doesn’t catch it.
34
35
36
37
|
# File 'lib/active_record/associations/association_proxy.rb', line 34
def ===(other)
load_target
other === @target
end
|
#aliased_table_name ⇒ Object
39
40
41
|
# File 'lib/active_record/associations/association_proxy.rb', line 39
def aliased_table_name
@reflection.klass.table_name
end
|
#conditions ⇒ Object
Also known as:
sql_conditions
43
44
45
|
# File 'lib/active_record/associations/association_proxy.rb', line 43
def conditions
@conditions ||= interpolate_sql(sanitize_sql(@reflection.options[:conditions])) if @reflection.options[:conditions]
end
|
#inspect ⇒ Object
76
77
78
79
|
# File 'lib/active_record/associations/association_proxy.rb', line 76
def inspect
reload unless loaded?
@target.inspect
end
|
#loaded ⇒ Object
63
64
65
|
# File 'lib/active_record/associations/association_proxy.rb', line 63
def loaded
@loaded = true
end
|
#loaded? ⇒ Boolean
59
60
61
|
# File 'lib/active_record/associations/association_proxy.rb', line 59
def loaded?
@loaded
end
|
#proxy_owner ⇒ Object
16
17
18
|
# File 'lib/active_record/associations/association_proxy.rb', line 16
def proxy_owner
@owner
end
|
#proxy_reflection ⇒ Object
20
21
22
|
# File 'lib/active_record/associations/association_proxy.rb', line 20
def proxy_reflection
@reflection
end
|
#proxy_respond_to? ⇒ Object
5
|
# File 'lib/active_record/associations/association_proxy.rb', line 5
alias_method :proxy_respond_to?, :respond_to?
|
#proxy_target ⇒ Object
24
25
26
|
# File 'lib/active_record/associations/association_proxy.rb', line 24
def proxy_target
@target
end
|
#reload ⇒ Object
53
54
55
56
57
|
# File 'lib/active_record/associations/association_proxy.rb', line 53
def reload
reset
load_target
self unless @target.nil?
end
|
#reset ⇒ Object
48
49
50
51
|
# File 'lib/active_record/associations/association_proxy.rb', line 48
def reset
@loaded = false
@target = nil
end
|
#respond_to?(symbol, include_priv = false) ⇒ Boolean
28
29
30
|
# File 'lib/active_record/associations/association_proxy.rb', line 28
def respond_to?(symbol, include_priv = false)
proxy_respond_to?(symbol, include_priv) || (load_target && @target.respond_to?(symbol, include_priv))
end
|
#target ⇒ Object
67
68
69
|
# File 'lib/active_record/associations/association_proxy.rb', line 67
def target
@target
end
|
#target=(target) ⇒ Object
71
72
73
74
|
# File 'lib/active_record/associations/association_proxy.rb', line 71
def target=(target)
@target = target
loaded
end
|