Class: Dynamoid::Persistence::Upsert
- Inherits:
-
Object
- Object
- Dynamoid::Persistence::Upsert
- Defined in:
- lib/dynamoid/persistence/upsert.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(model_class, partition_key:, sort_key:, attributes:, conditions:) ⇒ Upsert
constructor
A new instance of Upsert.
Constructor Details
#initialize(model_class, partition_key:, sort_key:, attributes:, conditions:) ⇒ Upsert
Returns a new instance of Upsert.
11 12 13 14 15 16 17 |
# File 'lib/dynamoid/persistence/upsert.rb', line 11 def initialize(model_class, partition_key:, sort_key:, attributes:, conditions:) @model_class = model_class @partition_key = partition_key @sort_key = sort_key @attributes = attributes.symbolize_keys @conditions = conditions end |
Class Method Details
.call(*args, **options) ⇒ Object
7 8 9 |
# File 'lib/dynamoid/persistence/upsert.rb', line 7 def self.call(*args, **) new(*args, **).call end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dynamoid/persistence/upsert.rb', line 19 def call UpdateValidations.validate_attributes_exist(@model_class, @attributes) if @model_class. @attributes[:updated_at] ||= DateTime.now.in_time_zone(Time.zone) end raw_attributes = update_item @model_class.new(undump_attributes(raw_attributes)) rescue Dynamoid::Errors::ConditionalCheckFailedException end |