mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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 ```
This commit is contained in:
parent
3a558aa2bc
commit
7c1b14f041
1 changed files with 4 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue