Module: Dynamoid::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- Components
- Defined in:
- lib/dynamoid/persistence.rb
Overview
Persistence is responsible for dumping objects to and marshalling objects from the datastore. It tries to reserialize values to be of the same type as when they were passed in, based on the fields in the class.
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary (collapse)
-
- (Object) new_record
(also: #new_record?)
Returns the value of attribute new_record.
Instance Method Summary (collapse)
-
- (Object) delete
Delete this object from the datastore and all indexes.
-
- (Object) destroy
Delete this object, but only after running callbacks for it.
-
- (Object) dump
Dump this object's attributes into hash form, fit to be persisted into the datastore.
-
- (Boolean) persisted?
Is this object persisted in the datastore? Required for some ActiveModel integration stuff.
-
- (Object) save(options = {})
Run the callbacks and then persist this object in the datastore.
Instance Attribute Details
- (Object) new_record Also known as: new_record?
Returns the value of attribute new_record
11 12 13 |
# File 'lib/dynamoid/persistence.rb', line 11 def new_record @new_record end |
Instance Method Details
- (Object) delete
Delete this object from the datastore and all indexes.
129 130 131 132 |
# File 'lib/dynamoid/persistence.rb', line 129 def delete delete_indexes Dynamoid::Adapter.delete(self.class.table_name, self.id) end |
- (Object) destroy
Delete this object, but only after running callbacks for it.
119 120 121 122 123 124 |
# File 'lib/dynamoid/persistence.rb', line 119 def destroy run_callbacks(:destroy) do self.delete end self end |
- (Object) dump
Dump this object's attributes into hash form, fit to be persisted into the datastore.
137 138 139 140 141 142 143 |
# File 'lib/dynamoid/persistence.rb', line 137 def dump Hash.new.tap do |hash| self.class.attributes.each do |attribute, | hash[attribute] = dump_field(self.read_attribute(attribute), [:type]) end end end |
- (Boolean) persisted?
Is this object persisted in the datastore? Required for some ActiveModel integration stuff.
94 95 96 |
# File 'lib/dynamoid/persistence.rb', line 94 def persisted? !new_record? end |
- (Object) save(options = {})
Run the callbacks and then persist this object in the datastore.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/dynamoid/persistence.rb', line 101 def save( = {}) if self.new_record? run_callbacks(:create) do run_callbacks(:save) do persist end end else run_callbacks(:save) do persist end end self end |