lib/superstore/persistence.rb in superstore-1.0.8 vs lib/superstore/persistence.rb in superstore-1.0.9

- old
+ new

@@ -40,11 +40,11 @@ def instantiate(id, attributes) allocate.tap do |object| object.instance_variable_set("@id", id) if id object.instance_variable_set("@new_record", false) object.instance_variable_set("@destroyed", false) - object.instance_variable_set("@attributes", typecast_persisted_attributes(object, attributes)) + object.instance_variable_set("@attributes", typecast_persisted_attributes(attributes)) end end def encode_attributes(attributes) encoded = {} @@ -62,10 +62,16 @@ def quote_columns(column_names) column_names.map { |name| "'#{name}'" } end - def typecast_persisted_attributes(object, attributes) + def typecast_persisted_attributes(attributes) + typecast_persisted_attributes! attributes.dup + end + + def typecast_persisted_attributes!(attributes) + attributes = attributes.dup + attributes.each do |key, value| if definition = attribute_definitions[key] attributes[key] = definition.instantiate(value) elsif key != primary_key attributes.delete(key)