diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-11-30 23:03:45 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-11-30 23:18:41 +0000 |
commit | 7a4949e7d5be37f64bf6a1f9dda6f427fbb5ac40 (patch) | |
tree | a3bec6f86002ca7fd94a2f89b3472793ce32ec00 /activerecord | |
parent | d5f7884dc5e74cd876f031ea2d4467cec18defbb (diff) | |
download | rails-7a4949e7d5be37f64bf6a1f9dda6f427fbb5ac40.tar.gz rails-7a4949e7d5be37f64bf6a1f9dda6f427fbb5ac40.tar.bz2 rails-7a4949e7d5be37f64bf6a1f9dda6f427fbb5ac40.zip |
consistency
Diffstat (limited to 'activerecord')
3 files changed, 16 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index 788d671ad1..4fdfe77bab 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -91,21 +91,21 @@ module ActiveRecord def _read_attribute(attr_name) attr_name = attr_name.to_s attr_name = self.class.primary_key if attr_name == 'id' - value = @attributes[attr_name] - unless value.nil? - if column = column_for_attribute(attr_name) - type_cast_attribute(column) + + unless @attributes[attr_name].nil? + type_cast_attribute(column_for_attribute(attr_name), @attributes[attr_name]) + end + end + + private + def type_cast_attribute(column, value) + if column + column.type_cast(value) else value end end - end - - def type_cast_attribute(column) #:nodoc: - column.type_cast(@attributes[column.name]) - end - private def attribute(attribute_name) read_attribute(attribute_name) end diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index b084fdc25b..d1eb3d5bfc 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -80,15 +80,15 @@ module ActiveRecord end end - def type_cast_attribute(column) - if self.class.serialized_attributes.include?(column.name) - @attributes[column.name].unserialized_value + def type_cast_attribute(column, value) + if column && self.class.serialized_attributes[column.name] + value.unserialized_value else super end end - def type_cast_attribute_for_write(column, attr_name, value) + def type_cast_attribute_for_write(column, value) if column && coder = self.class.serialized_attributes[column.name] Attribute.new(coder, value, :unserialized) else diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb index 650156f3cf..07499db9f0 100644 --- a/activerecord/lib/active_record/attribute_methods/write.rb +++ b/activerecord/lib/active_record/attribute_methods/write.rb @@ -29,7 +29,7 @@ module ActiveRecord column = column_for_attribute(attr_name) if column || @attributes.has_key?(attr_name) - @attributes[attr_name] = type_cast_attribute_for_write(column, attr_name, value) + @attributes[attr_name] = type_cast_attribute_for_write(column, value) else raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attr_name}'" end @@ -42,7 +42,7 @@ module ActiveRecord write_attribute(attribute_name, value) end - def type_cast_attribute_for_write(column, attr_name, value) + def type_cast_attribute_for_write(column, value) if column && column.number? convert_number_column_value(value) else |