lib/dynamoid/document.rb in dynamoid-1.1.0 vs lib/dynamoid/document.rb in dynamoid-1.2.0
- old
+ new
@@ -70,22 +70,22 @@
#
# @return [Dynamoid::Document] the saved document
#
# @since 0.2.0
def create(attrs = {})
- attrs[:type] ? attrs[:type].constantize.new(attrs).tap(&:save) : new(attrs).tap(&:save)
+ build(attrs).tap(&:save)
end
# Initialize a new object and immediately save it to the database. Raise an exception if persistence failed.
#
# @param [Hash] attrs Attributes with which to create the object.
#
# @return [Dynamoid::Document] the saved document
#
# @since 0.2.0
def create!(attrs = {})
- attrs[:type] ? attrs[:type].constantize.new(attrs).tap(&:save!) : new(attrs).tap(&:save!)
+ build(attrs).tap(&:save!)
end
# Initialize a new object.
#
# @param [Hash] attrs Attributes with which to create the object.
@@ -128,10 +128,12 @@
load(attrs)
end
end
def load(attrs)
- self.class.undump(attrs).each {|key, value| send "#{key}=", value }
+ self.class.undump(attrs).each do |key, value|
+ send("#{key}=", value) if self.respond_to?("#{key}=")
+ end
end
# An object is equal to another object if their ids are equal.
#
# @since 0.2.0