module TinyDyno::Persistable::ClassMethods

attribute_updates: {

“AttributeName” => {

value: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
action: "ADD", # accepts ADD, PUT, DELETE

}, def build_attribute_updates

change_record = []
changes.keys.each do |change_key|
  if self.class.attribute_names.include?(change_key)
    change_record << {:"#{ change_key}" => changes[change_key]}
  end
end
# keep this simple for now
# I don't see (yet) how to map the possible operations on dynamodb items
# into activerecord compatible schemas
# extend as use cases arise
# specification by example ...
attribute_updates = {}
change_record.each do |change|
  change_key = change.keys.first
  if change[change_key][1].nil?
    attribute_updates[change_key] = {
        action: 'DELETE'
    }
  else
    attribute_updates[change_key] = {
        value:  change[change_key][1],
        action: 'PUT'
    }
  end
end
attribute_updates

end

Public Instance Methods

create(attributes = nil, &block) click to toggle source

Prepare a request to be sent to the aws-sdk in compliance with docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#put_item-instance_method

# File lib/tiny_dyno/persistable.rb, line 102
def create(attributes = nil, &block)
  doc = new(attributes, &block)
  if doc.save
    doc
  else
    nil
  end
end