diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-21 21:15:01 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-21 22:29:21 +0530 |
commit | a68a3e9af6a02c9ce18d3eec87558241095ce8fb (patch) | |
tree | e19d89be8671cd04c29617a085749ced3fbf5593 /activerecord/lib/active_record/relation/query_methods.rb | |
parent | fc4f237864541f5012f9b8cc8e0ec81960377e55 (diff) | |
download | rails-a68a3e9af6a02c9ce18d3eec87558241095ce8fb.tar.gz rails-a68a3e9af6a02c9ce18d3eec87558241095ce8fb.tar.bz2 rails-a68a3e9af6a02c9ce18d3eec87558241095ce8fb.zip |
Simplify finder method definitions
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index ce3e4e8eed..8954f2d12b 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -8,11 +8,10 @@ module ActiveRecord class_eval <<-CEVAL def #{query_method}(*args) - spawn.tap do |new_relation| - new_relation.#{query_method}_values ||= [] - value = Array.wrap(args.flatten).reject {|x| x.blank? } - new_relation.#{query_method}_values += value if value.present? - end + new_relation = spawn + value = Array.wrap(args.flatten).reject {|x| x.blank? } + new_relation.#{query_method}_values += value if value.present? + new_relation end CEVAL end @@ -20,11 +19,10 @@ module ActiveRecord [:where, :having].each do |query_method| class_eval <<-CEVAL def #{query_method}(*args) - spawn.tap do |new_relation| - new_relation.#{query_method}_values ||= [] - value = build_where(*args) - new_relation.#{query_method}_values += [*value] if value.present? - end + new_relation = spawn + value = build_where(*args) + new_relation.#{query_method}_values += [*value] if value.present? + new_relation end CEVAL end @@ -34,9 +32,9 @@ module ActiveRecord class_eval <<-CEVAL def #{query_method}(value = true) - spawn.tap do |new_relation| - new_relation.#{query_method}_value = value - end + new_relation = spawn + new_relation.#{query_method}_value = value + new_relation end CEVAL end |