Module: Dynomite::Item::Locking
- Extended by:
- ActiveSupport::Concern
- Included in:
- Components
- Defined in:
- lib/dynomite/item/locking.rb
Instance Method Summary collapse
- #increment_lock_version ⇒ Object
-
#reset_lock_version_was ⇒ Object
Tricky: Must use dot notation for dirty tracking so old values are stored in case of a exceptional failure in the DynamoDB API put_item call in write/save.rb Example:.
Instance Method Details
#increment_lock_version ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/dynomite/item/locking.rb', line 25 def increment_lock_version return unless changed? reader = self.class.locking_field_name setter = "#{reader}=" send(setter, 0) if send(reader).nil? send(setter, send(reader) + 1) end |
#reset_lock_version_was ⇒ Object
Tricky: Must use dot notation for dirty tracking so old values are stored in case of a exceptional failure in the DynamoDB API put_item call in write/save.rb Example:
post.update_attribute(:title, nil) # update attribute bypasses validations
AWS Error:
The AttributeValue for a key attribute cannot contain an empty string value. IndexName: title-index, IndexKey: title (Aws::DynamoDB::Errors::ValidationException)
This allows the old value to be restored. And then the next update with a corrected title value saves successfully.
47 48 49 50 51 |
# File 'lib/dynomite/item/locking.rb', line 47 def reset_lock_version_was reader = self.class.locking_field_name setter = "#{reader}=" send(setter, send("#{reader}_was")) end |