lib/superstore/persistence.rb in superstore-2.4.2 vs lib/superstore/persistence.rb in superstore-2.4.3
- old
+ new
@@ -13,16 +13,10 @@
def delete_all
adapter.execute "TRUNCATE #{table_name}"
end
- def create(attributes = {}, &block)
- new(attributes, &block).tap do |object|
- object.save
- end
- end
-
def insert_record(id, attributes)
adapter.insert table_name, id, encode_attributes(attributes)
end
def update_record(id, attributes)
@@ -89,11 +83,11 @@
def persisted?
!(new_record? || destroyed?)
end
def save(*)
- new_record? ? create_self : update_self
+ create_or_update
end
def destroy
self.class.delete(id)
@destroyed = true
@@ -117,25 +111,20 @@
save!
end
alias update_attributes! update!
- def becomes(klass)
- became = klass.new
- became.instance_variable_set("@attributes", @attributes)
- became.instance_variable_set("@changed_attributes", changed_attributes || {})
- became.instance_variable_set("@new_record", new_record?)
- became.instance_variable_set("@destroyed", destroyed?)
- became
- end
-
def reload
clear_association_cache
@attributes = self.class.find(id).instance_variable_get('@attributes')
self
end
private
+
+ def create_or_update
+ new_record? ? create_self : update_self
+ end
def create_self
write :insert_record
end