Project

commutator

0.0
No commit activity in last 3 years
No release in over 3 years
Model object interface for Amazon DynamoDB.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.8
~> 10.0
~> 3.3

Runtime

 Project Readme

Commutator

Commutator is a Model object interface for Amazon DynamoDB.

Installation

Add this line to your application's Gemfile:

gem 'commutator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install commutator

Usage

TODO: Needs work

Basic usage example..

class Paint
  include Commutator::Model

  table_name "paint_products"

  attribute :name, :hex_color, type: :string
  attribute :created_ts, :updated_at, type: :integer

  validates :name, :hex_color, presence: true

  primary_key hash: :name, range: :created_ts

  before_put_item :prevent_dupes, :add_timestamps

  module Scopes
    def by_hex(hex)
      index_name('hex-index')
      with_key_condition_expression do |expression|
        expression.where('#? = :?', names: %w(hex_color), values: [hex_color.downcase])
      end      
    end
  end
  
  private
  
  def prevent_dupes(options)
    options.condition_expression.where_not do |expression|
      expression.where('name = :?', values: [name])
    end
  end
  
  def add_timestamps(options)
    now = Time.now.to_i
  
    options.item['updated_at'] = now
    options.item['created_at'] ||= now
  end
end

Color.by_hex("#BBAADD").first
Color.create(name: "Black", hex_color: "#000000")

Development

After checking out the repo, run bin/setup to install dependencies.

DynamoDB Local is also required for running tests tagged with :dynamo => true. Check the Amazon Documentation for Downloading and Running DynamoDB Local.

Then, run rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tablexi/commutator.

License

The gem is available as open source under the terms of the Apache License, Version 2.0.