class AWS::DynamoDB::AttributeCollection::UpdateBuilder

Used to build a batch of updates to an item’s attributes. See {AWS::DynamoDB::AttributeCollection#update} for more information.

Attributes

updates[R]

@private

Public Class Methods

new() click to toggle source

@private

# File lib/aws/dynamo_db/attribute_collection.rb, line 238
def initialize
  @updates = {}
end

Public Instance Methods

add(attributes) click to toggle source

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

# File lib/aws/dynamo_db/attribute_collection.rb, line 262
def add attributes
  attribute_updates("ADD", attributes)
end
delete(*args) click to toggle source

Deletes one or more attributes or attribute values. See {AWS::DynamoDB::AttributeCollection#delete} for more information.

# 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
merge!(attributes) click to toggle source
Alias for: set
put(attributes) click to toggle source
Alias for: set
set(attributes) click to toggle source

Replaces the values of one or more attributes. See {AWS::DynamoDB::AttributeCollection#set} for more information.

# 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
Also aliased as: put, merge!