Permalink
Browse files

Refactor Relation#only. No need to go through every option and test it.

  • Loading branch information...
1 parent d30fb46 commit ab1ab5fcec83e9a74807b034686ba08ad28ea8b6 @miloops miloops committed with tenderlove Sep 9, 2010
Showing with 6 additions and 8 deletions.
  1. +6 −8 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -78,14 +78,12 @@ def except(*skips)
def only(*onlies)
result = self.class.new(@klass, table)
- onlies.each do |only|
- if (Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS).include?(only)
- result.send(:"#{only}_values=", send(:"#{only}_values"))
- elsif Relation::SINGLE_VALUE_METHODS.include?(only)
- result.send(:"#{only}_value=", send(:"#{only}_value"))
- else
- raise "Invalid argument : #{only}"
- end
+ ((Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS) & onlies).each do |method|
+ result.send(:"#{method}_values=", send(:"#{method}_values"))
+ end
+
+ (Relation::SINGLE_VALUE_METHODS & onlies).each do |method|
+ result.send(:"#{method}_value=", send(:"#{method}_value"))
end
result

0 comments on commit ab1ab5f

Please sign in to comment.