Skip to content

Commit

Permalink
Rename variable name that returning type_for to type from column
Browse files Browse the repository at this point in the history
`column_for` was changed to `type_for` to return `type` object at
36bd52b. But variable name is still `column`. It is very confusing.
Rename variable name `column` to `type` for readability.
  • Loading branch information
kamipo committed Sep 10, 2016
1 parent cf5f55c commit 0d51369
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions activerecord/lib/active_record/relation/calculations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ def execute_simple_calculation(operation, column_name, distinct) #:nodoc:
result = @klass.connection.select_all(query_builder, nil, bound_attributes)
row = result.first
value = row && row.values.first
column = result.column_types.fetch(column_alias) do
type = result.column_types.fetch(column_alias) do
type_for(column_name)
end

type_cast_calculated_value(value, column, operation)
type_cast_calculated_value(value, type, operation)
end

def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
Expand Down Expand Up @@ -310,18 +310,16 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:

Hash[calculated_data.map do |row|
key = group_columns.map { |aliaz, col_name|
column = type_for(col_name) do
calculated_data.column_types.fetch(aliaz) do
Type.default_value
end
type = type_for(col_name) do
calculated_data.column_types.fetch(aliaz, Type.default_value)
end
type_cast_calculated_value(row[aliaz], column)
type_cast_calculated_value(row[aliaz], type)
}
key = key.first if key.size == 1
key = key_records[key] if associated

column_type = calculated_data.column_types.fetch(aggregate_alias) { type_for(column_name) }
[key, type_cast_calculated_value(row[aggregate_alias], column_type, operation)]
type = calculated_data.column_types.fetch(aggregate_alias) { type_for(column_name) }
[key, type_cast_calculated_value(row[aggregate_alias], type, operation)]
end]
end

Expand Down Expand Up @@ -356,7 +354,7 @@ def type_cast_calculated_value(value, type, operation = nil)
when "count" then value.to_i
when "sum" then type.deserialize(value || 0)
when "average" then value.respond_to?(:to_d) ? value.to_d : value
else type.deserialize(value)
else type.deserialize(value)
end
end

Expand Down

0 comments on commit 0d51369

Please sign in to comment.