Class: Dynamoid::Transactions::Mutation::UpdateFields::ItemUpdater
- Inherits:
-
Object
- Object
- Dynamoid::Transactions::Mutation::UpdateFields::ItemUpdater
- Defined in:
- lib/dynamoid/transactions/mutation/update_fields.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.
14 15 16 17 18 19 20 21 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 14 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.
12 13 14 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 12 def attributes_to_add @attributes_to_add end |
#attributes_to_delete ⇒ Object (readonly)
Returns the value of attribute attributes_to_delete.
12 13 14 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 12 def attributes_to_delete @attributes_to_delete end |
#attributes_to_remove ⇒ Object (readonly)
Returns the value of attribute attributes_to_remove.
12 13 14 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 12 def attributes_to_remove @attributes_to_remove end |
#attributes_to_set ⇒ Object (readonly)
Returns the value of attribute attributes_to_set.
12 13 14 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 12 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
44 45 46 47 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 44 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
50 51 52 53 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 50 def delete(attributes) validate_attribute_names!(attributes.keys) @attributes_to_delete.merge!(attributes) end |
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 23 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
38 39 40 41 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 38 def remove(*names) validate_attribute_names!(names) @attributes_to_remove += names end |
#set(attributes) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/dynamoid/transactions/mutation/update_fields.rb', line 27 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 |