You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::DynamoDB::AttributeCollection::UpdateBuilder

Inherits:
Object
  • Object
show all
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

Instance Method Details

#add(attributes) ⇒ Object

Adds to the values of one or more attributes. See AWS::DynamoDB::AttributeCollection#add for more information.



261
262
263
# File 'lib/aws/dynamo_db/attribute_collection.rb', line 261

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.



268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/aws/dynamo_db/attribute_collection.rb', line 268

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.



243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/aws/dynamo_db/attribute_collection.rb', line 243

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