Class: AWS::DynamoDB::AttributeCollection::UpdateBuilder
- Inherits:
-
Object
- Object
- AWS::DynamoDB::AttributeCollection::UpdateBuilder
- Includes:
- Types
- Defined in:
- lib/aws/dynamo_db/attribute_collection.rb
Overview
Used to build a batch of updates to an item’s attributes. See #update for more information.
Instance Attribute Summary collapse
- #updates ⇒ Object readonly
Instance Method Summary collapse
-
#add(attributes) ⇒ Object
Adds to the values of one or more attributes.
-
#delete(*args) ⇒ Object
Deletes one or more attributes or attribute values.
-
#initialize ⇒ UpdateBuilder
constructor
A new instance of UpdateBuilder.
-
#set(attributes) ⇒ Object
(also: #put, #merge!)
Replaces the values of one or more attributes.
Methods included from Types
#format_attribute_value, #value_from_response, #values_from_response_hash
Constructor Details
#initialize ⇒ UpdateBuilder
Returns a new instance of UpdateBuilder.
238 239 240 |
# File 'lib/aws/dynamo_db/attribute_collection.rb', line 238 def initialize @updates = {} end |
Instance Attribute Details
#updates ⇒ Object (readonly)
233 234 235 |
# File 'lib/aws/dynamo_db/attribute_collection.rb', line 233 def updates @updates end |
Instance Method Details
#add(attributes) ⇒ Object
Adds to the values of one or more attributes. See AWS::DynamoDB::AttributeCollection#add for more information.
262 263 264 |
# File 'lib/aws/dynamo_db/attribute_collection.rb', line 262 def add attributes attribute_updates("ADD", attributes) end |
#delete(*args) ⇒ Object
Deletes one or more attributes or attribute values. See AWS::DynamoDB::AttributeCollection#delete for more information.
269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/aws/dynamo_db/attribute_collection.rb', line 269 def delete *args if args.first.kind_of?(Hash) attribute_updates("DELETE", args.shift, :setify => true) else add_updates(args.inject({}) do |u, name| u.update(name.to_s => { :action => "DELETE" }) end) end end |
#set(attributes) ⇒ Object Also known as: put, merge!
Replaces the values of one or more attributes. See AWS::DynamoDB::AttributeCollection#set for more information.
244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/aws/dynamo_db/attribute_collection.rb', line 244 def set attributes to_delete = [] attributes = attributes.inject({}) do |attributes, (name, value)| if value == nil to_delete << name else attributes[name] = value end attributes end attribute_updates("PUT", attributes) delete(*to_delete) end |