Class: Dynamoid::Persistence::UpdateFields

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/persistence/update_fields.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class, partition_key:, sort_key:, attributes:, conditions:) ⇒ UpdateFields

Returns a new instance of UpdateFields.


11
12
13
14
15
16
17
# File 'lib/dynamoid/persistence/update_fields.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/update_fields.rb', line 7

def self.call(*args, **options)
  new(*args, **options).call
end

Instance Method Details

#callObject


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dynamoid/persistence/update_fields.rb', line 19

def call
  UpdateValidations.validate_attributes_exist(@model_class, @attributes)

  if Dynamoid::Config.timestamps
    @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