Module: DynamoRecord::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- Document
- Defined in:
- lib/dynamo_record/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#save ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dynamo_record/persistence.rb', line 69 def save = self.class. if id.nil? self.id = SecureRandom.uuid elsif @new_record # New item. Don't overwrite if id exists .merge!(condition_expression: 'id <> :s', expression_attribute_values: { ':s' => self.id }) end .merge!(item: attributes) response = self.class.client.put_item() @new_record = false true rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException false end |