aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-12-31 09:58:09 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-12-31 09:58:09 -0800
commit90c8972516d683f73dd2354f4b44e42d73c71a29 (patch)
tree0fe07d99e2cb30e11d487a6a63fb6489e795eea0
parent73a6a71addd1686faf017202e8e01e743eb16ef8 (diff)
parent1564b085e2bbf4e9d1077be95b94d70990e18e3f (diff)
downloadrails-90c8972516d683f73dd2354f4b44e42d73c71a29.tar.gz
rails-90c8972516d683f73dd2354f4b44e42d73c71a29.tar.bz2
rails-90c8972516d683f73dd2354f4b44e42d73c71a29.zip
Merge pull request #8664 from acapilleri/spawn_method
refatctoring of some code repetition in spawn_methods
-rw-r--r--activerecord/lib/active_record/relation/spawn_methods.rb18
1 files changed, 10 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb
index d417e82548..de784f9f57 100644
--- a/activerecord/lib/active_record/relation/spawn_methods.rb
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb
@@ -50,10 +50,7 @@ module ActiveRecord
# Post.order('id asc').except(:order) # discards the order condition
# Post.where('id > 10').order('id asc').except(:where) # discards the where condition but keeps the order
def except(*skips)
- result = Relation.new(klass, table, values.except(*skips))
- result.default_scoped = default_scoped
- result.extend(*extending_values) if extending_values.any?
- result
+ relation_with values.except(*skips)
end
# Removes any condition from the query other than the one(s) specified in +onlies+.
@@ -61,11 +58,16 @@ module ActiveRecord
# Post.order('id asc').only(:where) # discards the order condition
# Post.order('id asc').only(:where, :order) # uses the specified order
def only(*onlies)
- result = Relation.new(klass, table, values.slice(*onlies))
- result.default_scoped = default_scoped
- result.extend(*extending_values) if extending_values.any?
- result
+ relation_with values.slice(*onlies)
end
+ private
+
+ def relation_with(values) # :nodoc:
+ result = Relation.new(klass, table, values)
+ result.default_scoped = default_scoped
+ result.extend(*extending_values) if extending_values.any?
+ result
+ end
end
end