Navigation Menu

Skip to content

Commit

Permalink
Refactor Relation#only. No need to go through every option and test it.
Browse files Browse the repository at this point in the history
  • Loading branch information
miloops authored and tenderlove committed Sep 9, 2010
1 parent d30fb46 commit ab1ab5f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions activerecord/lib/active_record/relation/spawn_methods.rb
Expand Up @@ -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
Expand Down

0 comments on commit ab1ab5f

Please sign in to comment.