aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-08-16 05:33:22 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-11-16 02:42:24 +0900
commit7c1b14f04158102f68610128ae230941e85263a3 (patch)
treef139b8e8dce590499be4d45fa0ccac22f37d93bd /activerecord
parent3a558aa2bc8ce3834ee79ff3346bcf5d7debbbd0 (diff)
downloadrails-7c1b14f04158102f68610128ae230941e85263a3.tar.gz
rails-7c1b14f04158102f68610128ae230941e85263a3.tar.bz2
rails-7c1b14f04158102f68610128ae230941e85263a3.zip
Refactor `NullRelation#calculate`
Before: ```ruby def calculate(operation, _column_name) if [:count, :sum].include? operation group_values.any? ? Hash.new : 0 elsif [:average, :minimum, :maximum].include?(operation) && group_values.any? Hash.new else nil end end ``` After: ```ruby def calculate(operation, _column_name) case operation when :count, :sum group_values.any? ? Hash.new : 0 when :average, :minimum, :maximum group_values.any? ? Hash.new : nil end end ```
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/null_relation.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/null_relation.rb b/activerecord/lib/active_record/null_relation.rb
index 254550c378..2bb7ed6d5e 100644
--- a/activerecord/lib/active_record/null_relation.rb
+++ b/activerecord/lib/active_record/null_relation.rb
@@ -41,12 +41,11 @@ module ActiveRecord
end
def calculate(operation, _column_name)
- if [:count, :sum].include? operation
+ case operation
+ when :count, :sum
group_values.any? ? Hash.new : 0
- elsif [:average, :minimum, :maximum].include?(operation) && group_values.any?
- Hash.new
- else
- nil
+ when :average, :minimum, :maximum
+ group_values.any? ? Hash.new : nil
end
end