Class: Dynamoid::AdapterPlugin::AwsSdkV2::ItemUpdater
- Inherits:
-
Object
- Object
- Dynamoid::AdapterPlugin::AwsSdkV2::ItemUpdater
- Defined in:
- lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
Overview
Mimics behavior of the yielded object on DynamoDB’s update_item API (high level).
Constant Summary collapse
- ADD =
'ADD'.freeze
- DELETE =
'DELETE'.freeze
- PUT =
'PUT'.freeze
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.
1026 1027 1028 1029 1030 1031 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 1026 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.
1024 1025 1026 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 1024 def key @key end |
#range_key ⇒ Object (readonly)
Returns the value of attribute range_key.
1024 1025 1026 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 1024 def range_key @range_key end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
1024 1025 1026 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 1024 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.
1040 1041 1042 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 1040 def add(values) @additions.merge!(values) end |
#delete(values) ⇒ Object
Removes values from the sets of the given columns
1050 1051 1052 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 1050 def delete(values) @deletions.merge!(values) end |
#set(values) ⇒ Object
Replaces the values of one or more attributes
1057 1058 1059 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 1057 def set(values) @updates.merge!(values) end |
#to_h ⇒ Object
Returns an AttributeUpdates hash suitable for passing to the V2 Client API
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 1064 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, value: v } end @updates.each do |k, v| ret[k.to_s] = { action: PUT, value: v } end ret end |