Permalink
Browse files

consistency

  • Loading branch information...
1 parent d5f7884 commit 7a4949e7d5be37f64bf6a1f9dda6f427fbb5ac40 @jonleighton jonleighton committed Nov 30, 2011
@@ -91,21 +91,21 @@ def read_attribute(attr_name)
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
@@ -80,15 +80,15 @@ def set_serialized_attributes
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
@@ -29,7 +29,7 @@ def write_attribute(attr_name, value)
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 @@ def attribute=(attribute_name, value)
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

0 comments on commit 7a4949e

Please sign in to comment.