Module: ActiveRecord::Delegation
- Included in:
- Relation
- Defined in:
- activerecord/lib/active_record/relation/delegation.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'activerecord/lib/active_record/relation/delegation.rb', line 34
def method_missing(method, *args, &block)
if @klass.respond_to?(method)
::ActiveRecord::Delegation.delegate_to_scoped_klass(method)
scoping { @klass.send(method, *args, &block) }
elsif Array.method_defined?(method)
::ActiveRecord::Delegation.delegate method, :to => :to_a
to_a.send(method, *args, &block)
elsif arel.respond_to?(method)
::ActiveRecord::Delegation.delegate method, :to => :arel
arel.send(method, *args, &block)
else
super
end
end
|
Class Method Details
.delegate_to_scoped_klass(method) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'activerecord/lib/active_record/relation/delegation.rb', line 10
def self.delegate_to_scoped_klass(method)
if method.to_s =~ /\A[a-zA-Z_]\w*[!?]?\z/
module_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args, &block)
scoping { @klass.#{method}(*args, &block) }
end
RUBY
else
module_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args, &block)
scoping { @klass.send(#{method.inspect}, *args, &block) }
end
RUBY
end
end
|
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
26
27
28
29
30
|
# File 'activerecord/lib/active_record/relation/delegation.rb', line 26
def respond_to?(method, include_private = false)
super || Array.method_defined?(method) ||
@klass.respond_to?(method, include_private) ||
arel.respond_to?(method, include_private)
end
|