aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/delegation.rb
diff options
context:
space:
mode:
authorLauro Caetano <laurocaetano1@gmail.com>2013-12-03 18:30:13 -0200
committerLauro Caetano <laurocaetano1@gmail.com>2013-12-12 19:34:47 -0200
commitaa85bdba68eb981588cecfef9dea0c0fa3e1c673 (patch)
tree68bd2cd4280db4fb5dec47b4edfc760018849523 /activerecord/lib/active_record/relation/delegation.rb
parente87c3da2a291b54bce0be39ab2ec60ecd6d795a5 (diff)
downloadrails-aa85bdba68eb981588cecfef9dea0c0fa3e1c673.tar.gz
rails-aa85bdba68eb981588cecfef9dea0c0fa3e1c673.tar.bz2
rails-aa85bdba68eb981588cecfef9dea0c0fa3e1c673.zip
Use a whitelist to delegate methods to array
Diffstat (limited to 'activerecord/lib/active_record/relation/delegation.rb')
-rw-r--r--activerecord/lib/active_record/relation/delegation.rb24
1 files changed, 6 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb
index 1e15bddcdf..af6be24351 100644
--- a/activerecord/lib/active_record/relation/delegation.rb
+++ b/activerecord/lib/active_record/relation/delegation.rb
@@ -36,7 +36,11 @@ module ActiveRecord
# may vary depending on the klass of a relation, so we create a subclass of Relation
# for each different klass, and the delegations are compiled into that subclass only.
- delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to_ary, :to => :to_a
+ delegate :&, :+, :[], :all?, :collect, :detect, :each, :each_cons,
+ :each_with_index, :flat_map, :group_by, :include?, :length,
+ :map, :none?, :one?, :reverse, :sample, :second, :sort, :sort_by,
+ :to_ary, :to_set, :to_xml, :to_yaml, :to => :to_a
+
delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key,
:connection, :columns_hash, :to => :klass
@@ -84,9 +88,6 @@ module ActiveRecord
if @klass.respond_to?(method)
self.class.delegate_to_scoped_klass(method)
scoping { @klass.send(method, *args, &block) }
- elsif array_delegable?(method)
- self.class.delegate method, :to => :to_a
- to_a.send(method, *args, &block)
elsif arel.respond_to?(method)
self.class.delegate method, :to => :arel
arel.send(method, *args, &block)
@@ -109,28 +110,15 @@ module ActiveRecord
end
def respond_to?(method, include_private = false)
- super || array_delegable?(method) ||
- @klass.respond_to?(method, include_private) ||
+ super || @klass.respond_to?(method, include_private) ||
arel.respond_to?(method, include_private)
end
protected
- def array_delegable?(method)
- defined = Array.method_defined?(method)
- if defined && method.to_s.ends_with?('!')
- ActiveSupport::Deprecation.warn(
- "Association will no longer delegate #{method} to #to_a as of Rails 4.2. You instead must first call #to_a on the association to expose the array to be acted on."
- )
- end
- defined
- end
-
def method_missing(method, *args, &block)
if @klass.respond_to?(method)
scoping { @klass.send(method, *args, &block) }
- elsif array_delegable?(method)
- to_a.send(method, *args, &block)
elsif arel.respond_to?(method)
arel.send(method, *args, &block)
else