Class: AWS::DynamoDB::AttributeCollection::UpdateBuilder
- Inherits:
-
Object
- Object
- AWS::DynamoDB::AttributeCollection::UpdateBuilder
- 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 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.
-
#set(attributes) ⇒ Object
(also: #put, #merge!)
Replaces the values of one or more attributes.
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 |