class AWS::DynamoDB::AttributeCollection::UpdateBuilder
{AttributeCollection#update} for more information.
Used to build a batch of updates to an item’s attributes. See
def add attributes
Adds to the values of one or more attributes. See
def add attributes attribute_updates("ADD", attributes) end
def add_updates(new_updates)
def add_updates(new_updates) updates.merge!(new_updates) do |name, old, new| raise ArgumentError, "conflicting updates for attribute #{name}" end end
def attribute_updates(action, attributes, our_opts = {})
def attribute_updates(action, attributes, our_opts = {}) new_updates = attributes.inject({}) do |new_updates, (name, value)| name = name.to_s context = "in value for attribute #{name}" value = [value].flatten if our_opts[:setify] new_updates.update(name => { :action => action, :value => format_attribute_value(value, context) }) end add_updates(new_updates) end
def delete *args
Deletes one or more attributes or attribute values. See
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
def initialize
- Private: -
def initialize @updates = {} end
def set attributes
Replaces the values of one or more attributes. See
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