Sha256: bffa14fdb7999d28b7a25cf999b9d5b76899c8dce924b70a17f059f4c6eeffca

Contents?: true

Size: 764 Bytes

Versions: 3

Compression:

Stored size: 764 Bytes

Contents

# encoding: utf-8
module Dynamoid #:nodoc:

  # 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
    
    def initialize(attrs = {})
      @new_record = true
      @attributes ||= {}
      self.class.attributes.each {|att| write_attribute(att, attrs[att])}
    end
    
    def ==(other)
      other.respond_to?(:id) && other.id == self.id
    end
    
    module ClassMethods
      def create(attrs = {})
        obj = self.new(attrs)
        obj.save && obj.new_record = false
        obj
      end
      
      def build(attrs = {})
        self.new(attrs)
      end
    end
  end
  
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
dynamoid-0.0.3 lib/dynamoid/document.rb
dynamoid-0.0.2 lib/dynamoid/document.rb
Dynamoid-0.0.1 lib/dynamoid/document.rb