Permalink
Browse files

Merge pull request #8664 from acapilleri/spawn_method

refatctoring of some code repetition in spawn_methods
  • Loading branch information...
2 parents 73a6a71 + 1564b08 commit 90c8972516d683f73dd2354f4b44e42d73c71a29 @rafaelfranca rafaelfranca committed Dec 31, 2012
Showing with 10 additions and 8 deletions.
  1. +10 −8 activerecord/lib/active_record/relation/spawn_methods.rb
View
18 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -50,22 +50,24 @@ def merge!(other) # :nodoc:
# 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+.
#
# 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

0 comments on commit 90c8972

Please sign in to comment.