Module: Dynamoid::Document

Extended by:
ActiveSupport::Concern
Includes:
Components
Defined in:
lib/dynamoid/document.rb

Overview

This is the base module for all domain objects that need to be persisted to the database as documents.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary

Attributes included from Persistence

#new_record

Attributes included from Fields

#attributes

Instance Method Summary (collapse)

Methods included from Validations

#save, #save!, #valid?

Methods included from Persistence

#delete, #destroy, #dump, #persisted?, #save

Methods included from Indexes

#delete_indexes, #save_indexes

Methods included from Fields

#read_attribute, #update_attribute, #update_attributes, #write_attribute

Instance Method Details

- (Object) ==(other)

An object is equal to another object if their ids are equal.

Since:

  • 0.2.0



89
90
91
92
# File 'lib/dynamoid/document.rb', line 89

def ==(other)
  return false if other.nil?
  other.respond_to?(:id) && other.id == self.id
end

- (Dynamoid::Document) initialize(attrs = {})

Initialize a new object.

Parameters:

  • attrs (Hash) (defaults to: {})

    Attributes with which to create the object.

Since:

  • 0.2.0



76
77
78
79
80
81
82
83
84
# File 'lib/dynamoid/document.rb', line 76

def initialize(attrs = {})
  @new_record = true
  @attributes ||= {}
  incoming_attributes = self.class.undump(attrs)

  self.class.attributes.keys.each do |attribute|
    send "#{attribute}=", incoming_attributes[attribute]
  end
end

- (Dynamoid::Document) reload

Reload an object from the database -- if you suspect the object has changed in the datastore and you need those changes to be reflected immediately, you would call this method.

Returns:

Since:

  • 0.2.0



100
101
102
103
# File 'lib/dynamoid/document.rb', line 100

def reload
  self.attributes = self.class.find(self.id).attributes
  self
end