Module: TinyDyno::Persistable::ClassMethods

Defined in:
lib/tiny_dyno/persistable.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#create(attributes = nil, &block) ⇒ Object

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



89
90
91
92
93
94
95
96
# File 'lib/tiny_dyno/persistable.rb', line 89

def create(attributes = nil, &block)
  doc = new(attributes, &block)
  if doc.save
    doc
  else
    nil
  end
end