lib/dynamoid/document.rb in dynamoid-0.1.1 vs lib/dynamoid/document.rb in dynamoid-0.1.2

- old
+ new

@@ -4,28 +4,15 @@ # This is the base module for all domain objects that need to be persisted to # the database as documents. module Document extend ActiveSupport::Concern include Dynamoid::Components - - attr_accessor :new_record - alias :new_record? :new_record - def initialize(attrs = {}) - @new_record = true - @attributes ||= {} - self.class.attributes.each {|att| write_attribute(att, attrs[att])} + included do + Dynamoid::Config.included_models << self end - def persisted? - !new_record? - end - - def ==(other) - other.respond_to?(:id) && other.id == self.id - end - module ClassMethods def create(attrs = {}) obj = self.new(attrs) obj.run_callbacks(:create) do obj.save && obj.new_record = false @@ -34,9 +21,25 @@ end def build(attrs = {}) self.new(attrs) end + end + + def initialize(attrs = {}) + @new_record = true + @attributes ||= {} + attrs = self.class.undump(attrs) + self.class.attributes.keys.each {|att| write_attribute(att, attrs[att])} + end + + def ==(other) + other.respond_to?(:id) && other.id == self.id + end + + def reload + self.attributes = self.class.find(self.id).attributes + self end end end \ No newline at end of file