Gomon

Ruby wrappers around mongodb cli tools.

Prerequisites

Build Status

This gem depends on no other gems. It is tested agains many rubies: 1.8.7, 1.9.2, 1.9.3, jruby-18, jruby-19, rubinius-18, rubinius-19.

It assumes the presence of mongorestore and mongodump commands. It was built around the latest mongodb tools at the moment of this writing, meaning version 2.2.2. Therefore, it is possible that arguments format and/or names have changed from previous versions, making them potentially not compatible with Gomon.

Installation

Directly : gem install gomon

Gemfile : gem 'gomon'

Usage

The tools currently supported are mongodump and mongorestore.
They are wrapped in Gomon::Dump and Gomon::Restore respectively.

These two classes are used in the same way: first, instantiate the object, then, invoke call without arguments on it. In most cases, the only difference of usage will be the options passed to the constructor.

Example

> gd = Gomon::Dump.new uri: "mongodb://user:pass@host:12345/database", other: 'journal'
> gd.cmd_string
=> "mongodump --host 'host' --port '12345' --username 'user' --password 'pass' --db 'database' --journal"
> gd.call
# Dumping `database` from host...
# Executing: mongodump --host 'host' --port '12345' --username 'user' --password 'pass' --db 'database' --journal
# ....
# Done dumping.
=> nil

Options

The two classes accepts a hash of options when initializing, as in gd = Gomon::Dumper.new(db: 'gem_test'). You can also supply this hash later by calling gd.handle_options(opts), both have the same effect. When you add options this way, some specific rules apply :

  • If the key :uri is present, its value will be parsed and split to retrieve the username, password, host, port, and database;
  • Specific to Gomon::Restore: the option value for the key :path will be used as its last argument, as is.

Adding options using the following methods will not trigger the specific behaviours listed above.

  • add_option(key, value): adds the option. It will override previous ones.
  • add_options(hash): adds the options. It will override previous ones.
  • `add_singular_option(string): adds the singular option. Duplicates will be removed.
  • `add_singular_options(string_or_array): adds the singular options. Duplicates will be removed.

Options keys will always be casted as symbols, while values will always be casted as string.

No validation of options is done, so you should be careful about supplying only options accepted by mongodump or mongorestore. Refer to the MongoDB Manual for more on the topic.

Contributions

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. In the first case, please include a use-case.
  2. Fork the repository on Github, make a feature branch, work on this branch.
  3. If necessary, write a test which shows that the bug was fixed or that the feature works as expected.
  4. Send a pull request and annoy us until we notice it. :)

Changelog

  • 0.4: Better options handling. Many ruby versions are now supported.
  • 0.3: Ruby 1.8 support
  • 0.2: Test coverage.
  • 0.1: First version. Provices basic functionnality for Gomon::Dump & Gomon::Restore