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
Attributes included from Fields
Instance Method Summary (collapse)
-
- (Object) ==(other)
An object is equal to another object if their ids are equal.
-
- (Object) hash_key
Return an object's hash key, regardless of what it might be called to the object.
-
- (Object) hash_key=(key)
Assign an object's hash key, regardless of what it might be called to the object.
-
- (Dynamoid::Document) initialize(attrs = {})
Initialize a new object.
-
- (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.
Methods included from Validations
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.
118 119 120 121 |
# File 'lib/dynamoid/document.rb', line 118 def ==(other) return false if other.nil? other.respond_to?(:hash_key) && other.hash_key == self.hash_key end |
- (Object) hash_key
Return an object's hash key, regardless of what it might be called to the object.
138 139 140 |
# File 'lib/dynamoid/document.rb', line 138 def hash_key self.send(self.class.hash_key) end |
- (Object) hash_key=(key)
Assign an object's hash key, regardless of what it might be called to the object.
145 146 147 |
# File 'lib/dynamoid/document.rb', line 145 def hash_key=(key) self.send("#{self.class.hash_key}=".to_sym, key) end |
- (Dynamoid::Document) initialize(attrs = {})
Initialize a new object.
105 106 107 108 109 110 111 112 113 |
# File 'lib/dynamoid/document.rb', line 105 def initialize(attrs = {}) self.class.send(:field, self.class.hash_key) unless self.respond_to?(self.class.hash_key) @new_record = true @attributes ||= {} @associations ||= {} self.class.undump(attrs).each {|key, value| send "#{key}=", value } 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.
129 130 131 132 133 |
# File 'lib/dynamoid/document.rb', line 129 def reload self.attributes = self.class.find(self.hash_key).attributes @associations.values.each(&:reset) self end |