Module: Aws::Record::DirtyTracking
- Included in:
- Aws::Record
- Defined in:
- lib/aws-record/record/dirty_tracking.rb
Defined Under Namespace
Modules: DirtyTrackingClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#attribute_dirty!(name) ⇒ Object
Mark that an attribute is changing.
-
#attribute_dirty?(name) ⇒ Boolean
Returns
true
if the specified attribute has any dirty changes,false
otherwise. -
#attribute_was(name) ⇒ Object
Returns the original value of the specified attribute.
- #clean! ⇒ Object private
-
#destroyed? ⇒ Boolean
Returns
true
if the model has been destroyed,false
otherwise. -
#dirty ⇒ Array
Returns an array with the name of the attributes with dirty changes.
-
#dirty? ⇒ Boolean
Returns
true
if any attributes have dirty changes,false
otherwise. -
#new_record? ⇒ Boolean
Returns
true
if the model is newly initialized,false
otherwise. -
#persisted? ⇒ Boolean
Returns
true
if the model is not new and has not been deleted,false
otherwise. -
#reload! ⇒ self
Fetches attributes for this instance of an item from Amazon DynamoDB using its primary key and the find(*) class method.
-
#rollback!(names = dirty) ⇒ Object
Restores all attributes to their original values.
-
#rollback_attribute!(name) ⇒ Object
Restores the attribute specified to its original value.
- #save ⇒ Object
Class Method Details
.included(sub_class) ⇒ Object
7 8 9 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 7 def self.included(sub_class) sub_class.extend(DirtyTrackingClassMethods) end |
Instance Method Details
#attribute_dirty!(name) ⇒ Object
Mark that an attribute is changing. This is useful in situations where it is necessary to track that the value of an attribute is changing in-place.
84 85 86 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 84 def attribute_dirty!(name) @data.attribute_dirty!(name) end |
#attribute_dirty?(name) ⇒ Boolean
Returns true
if the specified attribute has any dirty changes, false
otherwise.
27 28 29 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 27 def attribute_dirty?(name) @data.attribute_dirty?(name) end |
#attribute_was(name) ⇒ Object
Returns the original value of the specified attribute.
46 47 48 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 46 def attribute_was(name) @data.attribute_was(name) end |
#clean! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
256 257 258 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 256 def clean! @data.clean! end |
#destroyed? ⇒ Boolean
Returns true
if the model has been destroyed, false
otherwise.
187 188 189 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 187 def destroyed? @data.destroyed? end |
#dirty ⇒ Array
Returns an array with the name of the attributes with dirty changes.
103 104 105 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 103 def dirty @data.dirty end |
#dirty? ⇒ Boolean
Returns true
if any attributes have dirty changes, false
otherwise.
123 124 125 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 123 def dirty? @data.dirty? end |
#new_record? ⇒ Boolean
Returns true
if the model is newly initialized, false
otherwise.
165 166 167 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 165 def new_record? @data.new_record? end |
#persisted? ⇒ Boolean
Returns true
if the model is not new and has not been deleted, false
otherwise.
145 146 147 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 145 def persisted? @data.persisted? end |
#reload! ⇒ self
Fetches attributes for this instance of an item from Amazon DynamoDB using its primary key and the find(*) class method.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 198 def reload! primary_key = self.class.keys.values.inject({}) do |memo, key| memo[key] = send(key) memo end record = self.class.find(primary_key) unless record.nil? @data = record.instance_variable_get("@data") else raise Errors::NotFound.new("No record found") end clean! self end |
#rollback!(names = dirty) ⇒ Object
Restores all attributes to their original values.
251 252 253 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 251 def rollback!(names = dirty) Array(names).each { |name| rollback_attribute!(name) } end |
#rollback_attribute!(name) ⇒ Object
Restores the attribute specified to its original value.
232 233 234 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 232 def rollback_attribute!(name) @data.rollback_attribute!(name) end |
#save ⇒ Object
263 264 265 |
# File 'lib/aws-record/record/dirty_tracking.rb', line 263 def save(*) super.tap { clean! } end |