diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-09 15:30:44 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-09-09 15:30:44 -0300 |
commit | 90c114de67483109f0c6871b2266dd1ad2582b7a (patch) | |
tree | b4137acff37d187ccdbc6604d223580819ebe679 | |
parent | e3246ef5b50d48aa86ee41a161b42611a936f4fb (diff) | |
download | rails-90c114de67483109f0c6871b2266dd1ad2582b7a.tar.gz rails-90c114de67483109f0c6871b2266dd1ad2582b7a.tar.bz2 rails-90c114de67483109f0c6871b2266dd1ad2582b7a.zip |
Refactor Relation#only. No need to go through every option and test it.
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index d833832faf..ba8efb5409 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -78,14 +78,12 @@ module ActiveRecord 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 |