Class: Dynamoid::AdapterPlugin::AwsSdkV3::ItemUpdater
- Inherits:
-
Object
- Object
- Dynamoid::AdapterPlugin::AwsSdkV3::ItemUpdater
- Defined in:
- lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb
Overview
Mimics behavior of the yielded object on DynamoDB’s update_item API (high level).
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#range_key ⇒ Object
readonly
Returns the value of attribute range_key.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
-
#add(values) ⇒ Object
Adds the given values to the values already stored in the corresponding columns.
-
#delete(values) ⇒ Object
Removes values from the sets of the given columns.
-
#initialize(table, key, range_key = nil) ⇒ ItemUpdater
constructor
A new instance of ItemUpdater.
-
#set(values) ⇒ Object
Replaces the values of one or more attributes.
-
#to_h ⇒ Object
Returns an AttributeUpdates hash suitable for passing to the V2 Client API.
Constructor Details
#initialize(table, key, range_key = nil) ⇒ ItemUpdater
Returns a new instance of ItemUpdater.
11 12 13 14 15 16 17 18 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb', line 11 def initialize(table, key, range_key = nil) @table = table @key = key @range_key = range_key @additions = {} @deletions = {} @updates = {} end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb', line 9 def key @key end |
#range_key ⇒ Object (readonly)
Returns the value of attribute range_key.
9 10 11 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb', line 9 def range_key @range_key end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
9 10 11 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb', line 9 def table @table end |
Instance Method Details
#add(values) ⇒ Object
Adds the given values to the values already stored in the corresponding columns. The column must contain a Set or a number.
27 28 29 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb', line 27 def add(values) @additions.merge!(sanitize_attributes(values)) end |
#delete(values) ⇒ Object
Removes values from the sets of the given columns
37 38 39 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb', line 37 def delete(values) @deletions.merge!(sanitize_attributes(values)) end |
#set(values) ⇒ Object
Replaces the values of one or more attributes
44 45 46 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb', line 44 def set(values) @updates.merge!(sanitize_attributes(values)) end |
#to_h ⇒ Object
Returns an AttributeUpdates hash suitable for passing to the V2 Client API
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb', line 51 def to_h ret = {} @additions.each do |k, v| ret[k.to_s] = { action: ADD, value: v } end @deletions.each do |k, v| ret[k.to_s] = { action: DELETE } ret[k.to_s][:value] = v unless v.nil? end @updates.each do |k, v| ret[k.to_s] = { action: PUT, value: v } end ret end |