diff options
Diffstat (limited to 'activerecord/lib')
10 files changed, 16 insertions, 34 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index 5778640525..e576ec4d40 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -244,6 +244,10 @@ module ActiveRecord def writer_method(name, class_name, mapping, allow_nil, converter) define_method("#{name}=") do |part| klass = class_name.constantize + if part.is_a?(Hash) + part = klass.new(*part.values) + end + unless part.is_a?(klass) || converter.nil? || part.nil? part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part) end diff --git a/activerecord/lib/active_record/attribute_assignment.rb b/activerecord/lib/active_record/attribute_assignment.rb index c4cf084a04..40e2918777 100644 --- a/activerecord/lib/active_record/attribute_assignment.rb +++ b/activerecord/lib/active_record/attribute_assignment.rb @@ -126,8 +126,8 @@ module ActiveRecord def read_value return if values.values.compact.empty? - @column = object.class.reflect_on_aggregation(name.to_sym) || object.column_for_attribute(name) - klass = column.klass + @column = object.column_for_attribute(name) + klass = column ? column.klass : nil if klass == Time read_time @@ -186,8 +186,7 @@ module ActiveRecord positions = (1..max_position) validate_required_parameters!(positions) - set_values = values.values_at(*positions) - klass.new(*set_values) + values.slice(*positions) end # Checks whether some blank date parameter exists. Note that this is different diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/float.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/float.rb index 9753d71461..77dd97e140 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/float.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/float.rb @@ -5,9 +5,8 @@ module ActiveRecord class Float < Type::Float include Infinity - def type_cast(value) + def cast_value(value) case value - when nil then nil when 'Infinity' then ::Float::INFINITY when '-Infinity' then -::Float::INFINITY when 'NaN' then ::Float::NAN diff --git a/activerecord/lib/active_record/type/binary.rb b/activerecord/lib/active_record/type/binary.rb index 9d10c91fc1..bc93f6e1bf 100644 --- a/activerecord/lib/active_record/type/binary.rb +++ b/activerecord/lib/active_record/type/binary.rb @@ -9,10 +9,6 @@ module ActiveRecord true end - def klass - ::String - end - def type_cast_for_database(value) Data.new(super) end diff --git a/activerecord/lib/active_record/type/decimal.rb b/activerecord/lib/active_record/type/decimal.rb index 6eed005345..a9db51c6ba 100644 --- a/activerecord/lib/active_record/type/decimal.rb +++ b/activerecord/lib/active_record/type/decimal.rb @@ -7,10 +7,6 @@ module ActiveRecord :decimal end - def klass - ::BigDecimal - end - def type_cast_for_schema(value) value.to_s end diff --git a/activerecord/lib/active_record/type/float.rb b/activerecord/lib/active_record/type/float.rb index dc50dae328..42eb44b9a9 100644 --- a/activerecord/lib/active_record/type/float.rb +++ b/activerecord/lib/active_record/type/float.rb @@ -7,10 +7,6 @@ module ActiveRecord :float end - def klass - ::Float - end - alias type_cast_for_database type_cast private diff --git a/activerecord/lib/active_record/type/integer.rb b/activerecord/lib/active_record/type/integer.rb index 1e2147dec9..08477d1303 100644 --- a/activerecord/lib/active_record/type/integer.rb +++ b/activerecord/lib/active_record/type/integer.rb @@ -7,10 +7,6 @@ module ActiveRecord :integer end - def klass - ::Fixnum - end - alias type_cast_for_database type_cast private diff --git a/activerecord/lib/active_record/type/numeric.rb b/activerecord/lib/active_record/type/numeric.rb index 9cc6411e77..d5cb13233c 100644 --- a/activerecord/lib/active_record/type/numeric.rb +++ b/activerecord/lib/active_record/type/numeric.rb @@ -5,13 +5,14 @@ module ActiveRecord true end - def type_cast_for_write(value) - case value - when true then 1 - when false then 0 - when ::String then value.presence - else super - end + def type_cast(value) + value = case value + when true then 1 + when false then 0 + when ::String then value.presence + else value + end + super(value) end def changed?(old_value, new_value) # :nodoc: diff --git a/activerecord/lib/active_record/type/string.rb b/activerecord/lib/active_record/type/string.rb index b3f6ca7691..3b1554bd5a 100644 --- a/activerecord/lib/active_record/type/string.rb +++ b/activerecord/lib/active_record/type/string.rb @@ -9,10 +9,6 @@ module ActiveRecord true end - def klass - ::String - end - private def cast_value(value) diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb index c072c1e2b6..4bc3086db3 100644 --- a/activerecord/lib/active_record/type/value.rb +++ b/activerecord/lib/active_record/type/value.rb @@ -48,7 +48,6 @@ module ActiveRecord end def klass # :nodoc: - ::Object end def type_cast_for_write(value) # :nodoc: |