Class: Dynamoid::TransactionWrite::ItemUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/transaction_write/item_updater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class) ⇒ ItemUpdater

Returns a new instance of ItemUpdater.



8
9
10
11
12
13
14
15
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 8

def initialize(model_class)
  @model_class = model_class

  @attributes_to_set = {}
  @attributes_to_add = {}
  @attributes_to_delete = {}
  @attributes_to_remove = []
end

Instance Attribute Details

#attributes_to_addObject (readonly)

Returns the value of attribute attributes_to_add.



6
7
8
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 6

def attributes_to_add
  @attributes_to_add
end

#attributes_to_deleteObject (readonly)

Returns the value of attribute attributes_to_delete.



6
7
8
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 6

def attributes_to_delete
  @attributes_to_delete
end

#attributes_to_removeObject (readonly)

Returns the value of attribute attributes_to_remove.



6
7
8
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 6

def attributes_to_remove
  @attributes_to_remove
end

#attributes_to_setObject (readonly)

Returns the value of attribute attributes_to_set.



6
7
8
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 6

def attributes_to_set
  @attributes_to_set
end

Instance Method Details

#add(attributes) ⇒ Object

increments a number or adds to a set, starts at 0 or [] if it doesn’t yet exist



33
34
35
36
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 33

def add(attributes)
  validate_attribute_names!(attributes.keys)
  @attributes_to_add.merge!(attributes)
end

#delete(attributes) ⇒ Object

deletes a value or values from a set



39
40
41
42
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 39

def delete(attributes)
  validate_attribute_names!(attributes.keys)
  @attributes_to_delete.merge!(attributes)
end

#empty?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 17

def empty?
  [@attributes_to_set, @attributes_to_add, @attributes_to_delete, @attributes_to_remove].all?(&:empty?)
end

#remove(*names) ⇒ Object

adds to array of fields for use in REMOVE update expression



27
28
29
30
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 27

def remove(*names)
  validate_attribute_names!(names)
  @attributes_to_remove += names
end

#set(attributes) ⇒ Object



21
22
23
24
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 21

def set(attributes)
  validate_attribute_names!(attributes.keys)
  @attributes_to_set.merge!(attributes)
end