wiki:WikiStart
Last modified 8 months ago Last modified on 09/12/11 19:01:10

Ruby-Mongrel2

A complete Ruby connector for Mongrel2.

This library includes configuration-database ORM classes, a Ruby implementation of the 'm2sh' tool, a configuration DSL for generating config databases in pure Ruby, a Control port interface object, and handler classes for creating applications or higher-level frameworks.

It differs from the original Mongrel2 Ruby library (m2r), and the mongrel2-rack library in several ways:

  • It uses the C extension for 0MQ (zmq) instead of the FFI one. If you strongly prefer the FFI library, both of the other Mongrel2 libraries use it, so you'll want to stick to one of them.
  • It doesn't come with a Rack handler, or Rails examples, or anything fancy. I intend to build my own webby framework bits around Mongrel2, and I thought maybe someone else might want to as well. If you don't, well again, there are two other libraries for you.
  • It includes configuration stuff. I want to make tools that use the Mongrel2 config database, so I wrote config classes. Sequel::Model made it stupid-easy. There's also a DSL for generating a config database, too, mostly because I found it an interesting exercise, and I like the way it looks.

Installation

$ gem install mongrel2

This library uses Jeremy Hinegardner's 'amalgalite' library for the config ORM classes, but it will also fall back to using the sqlite3 library instead, if you prefer that. Just load it before you require 'mongrel2':

# Loading the sqlite3 library explicitly
$ rspec -rsqlite3 -cfp spec
>>> Using SQLite3 1.3.4 for DB access.
.....[...]

Finished in 5.53 seconds
102 examples, 0 failures

# No -rsqlite3 means amalgalite loads first.
$ rspec -cfp spec
>>> Using Amalgalite 1.1.2 for DB access.
.....[...]

Finished in 3.67 seconds
102 examples, 0 failures

Usage

The library consists of three major parts: the Config ORM classes, the Handler classes, and the Control class.

Config ORM Classes

There's one class per table like with most ORMs, a Mongrel2::Config::DSL mixin for adding the Ruby configuration DSL to your namespace, and the top-level Mongrel2::Config class, which manages the database connection, installs the schema, etc.

Handler Classes

The main handler class is, unsurprisingly, Mongrel2::Handler. It uses a Mongrel2::Connection object to talk to the server, wrapping the request data up in a Mongrel2::Request object, and expecting a Mongrel2::Response in response.

There are specialized Request classes for each of the kinds of requests Mongrel2 sends:

These are all overridable if you should want a more-specialized class for one of them.

The Mongrel2::Handler class itself has documentation on how to write your own handlers.

The Control Class

The Mongrel2::Control class is an object interface to the Mongrel2 control port. It can be used to stop and restart the server, check its status, etc.

Other Classes

There are a few other classes and modules, too:

Contributing

You can check out the current development source with Mercurial via its main Mercurial repo. Or if you prefer Git, via its Github mirror.

After checking out the source, run:

$ rake newb

This task will install any missing dependencies, run the tests/specs, and generate the API documentation.

Starting Points

If you're new to Trac, here are some good places to start:

For a complete list of local wiki pages, see TitleIndex.