Skip to content
rodrigues edited this page Oct 26, 2012 · 18 revisions

Ripple is a rich Ruby client for Riak, Basho’s distributed database. It includes two namespaces:

  • Riak contains a basic wrapper around typical operations, including bucket manipulation, object CRUD, link-walking, and map-reduce.
  • Ripple contains an ActiveModel-compatible modeling layer that is inspired by ActiveRecord, DataMapper, and MongoMapper.

Documentation
Wiki
Links

Installation:

gem install ripple

Or git clone git://github.com/basho/ripple.git

Basic Riak::Client example

require 'riak'
  
# Create a client interface
client = Riak::Client.new
  
# Retrieve a bucket
bucket = client.bucket("doc")  # a Riak::Bucket

# Get an object from the bucket
object = bucket.get("index.html")   # a Riak::RObject

# Change the object's data and save
object.data = "Hello, world!"
object.store

# Reload an object you already have
object.reload                  # Works if you have the key and vclock, using conditional GET
object.reload :force => true   # Reloads whether you have the vclock or not

# Access more like a hash, client[bucket][key]
client['doc']['index.html']   # the Riak::RObject

# Create a new object
new_one = Riak::RObject.new(bucket, "application.js")
new_one.content_type = "application/javascript" # You must set the content type.
new_one.data = "alert('Hello, World!')"
new_one.store

MapReduce Example

# Assuming you've already instantiated a client, get the album titles for The Beatles
results = Riak::MapReduce.new(client).
                add("artists","Beatles").
                link(:bucket => "albums").
                map("function(v){ return [JSON.parse(v.values[0].data).title]; }",
                          :keep => true).run

p results # => ["Please Please Me", "With The Beatles", "A Hard Day's Night", 
          #     "Beatles For Sale", "Help!", "Rubber Soul",
          #     "Revolver", "Sgt. Pepper's Lonely Hearts Club Band", 
          #     "Magical Mystery Tour",   "The Beatles", 
          #     "Yellow Submarine", "Abbey Road", "Let It Be"]

Document Model Example

require 'ripple'

class Email
  include Ripple::Document
  property :from,    String, :presence => true
  property :to,      String, :presence => true
  property :sent,    Time,   :default => proc { Time.now }
  property :body,    String
end

email = Email.find("37458abc752f8413e")  # GET /raw/emails/37458abc752f8413e
email.from = "[email protected]"
email.save                               # PUT /raw/emails/37458abc752f8413e

reply = Email.new
reply.from = "[email protected]"
reply.to   = "[email protected]"
reply.body = "Riak is a good fit for scalable Ruby apps."
reply.save                               # POST /raw/emails (Riak-assigned key)

How to Contribute

  • Fork the project on Github. If you have already forked, use git pull —rebase to reapply your changes on top of the mainline. Example:
    $ git checkout master
    $ git pull --rebase seancribbs master
  • Create a topic branch. If you’ve already created a topic branch, rebase it on top of changes from the mainline “master” branch. Examples:
    • New branch:
      $ git checkout -b topic
    • Existing branch:
      $ git rebase master
  • Write an RSpec example, set of examples, and/or Cucumber story that demonstrate the necessity and validity of your changes. Patches without specs will most often be ignored. Just do it, you’ll thank me later. Documentation patches need no specs, of course.
  • Make your feature addition or bug fix. Make your specs and stories pass (green).
  • Run the suite using multiruby or rvm to ensure cross-version compatibility.
  • Cleanup any trailing whitespace in your code (try whitespace-mode in Emacs, or “Remove Trailing Spaces in Document” in the “Text” bundle in Textmate).
  • Commit, do not mess with Rakefile or VERSION. If related to an existing issue in the tracker, include “Closes #X” in the commit message (where X is the issue number).
  • Send me a pull request.