1
0
Fork 0
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:
Ryuta Kamizono 2016-08-16 05:33:22 +09:00
parent 3a558aa2bc
commit 7c1b14f041

View file

@ -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