Class: Dynamoid::TransactionWrite::ItemUpdater
- Inherits:
-
Object
- Object
- Dynamoid::TransactionWrite::ItemUpdater
- Defined in:
- lib/dynamoid/transaction_write/item_updater.rb
Instance Attribute Summary collapse
-
#attributes_to_add ⇒ Object
readonly
Returns the value of attribute attributes_to_add.
-
#attributes_to_delete ⇒ Object
readonly
Returns the value of attribute attributes_to_delete.
-
#attributes_to_remove ⇒ Object
readonly
Returns the value of attribute attributes_to_remove.
-
#attributes_to_set ⇒ Object
readonly
Returns the value of attribute attributes_to_set.
Instance Method Summary collapse
-
#add(attributes) ⇒ Object
increments a number or adds to a set, starts at 0 or [] if it doesn’t yet exist.
-
#delete(attributes) ⇒ Object
deletes a value or values from a set.
- #empty? ⇒ Boolean
-
#initialize(model_class) ⇒ ItemUpdater
constructor
A new instance of ItemUpdater.
-
#remove(*names) ⇒ Object
adds to array of fields for use in REMOVE update expression.
- #set(attributes) ⇒ Object
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_add ⇒ Object (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_delete ⇒ Object (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_remove ⇒ Object (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_set ⇒ Object (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
38 39 40 41 |
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 38 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
44 45 46 47 |
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 44 def delete(attributes) validate_attribute_names!(attributes.keys) @attributes_to_delete.merge!(attributes) end |
#empty? ⇒ 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
32 33 34 35 |
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 32 def remove(*names) validate_attribute_names!(names) @attributes_to_remove += names end |
#set(attributes) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/dynamoid/transaction_write/item_updater.rb', line 21 def set(attributes) validate_attribute_names!(attributes.keys) if Dynamoid.config.store_attribute_with_nil_value @attributes_to_set.merge!(attributes) else @attributes_to_set.merge!(attributes.reject { |_, v| v.nil? }) @attributes_to_remove += attributes.select { |_, v| v.nil? }.keys end end |