zentradi

Zentradi provides a [wannabe] minimalistic set of tools for managing the mongodb ruby driver.

For now this is basically my playground for experimenting with mongodb.

Developed mainly under ruby 1.9.1, using bundler for development mode dependencies management.

Usage

The class just acts as a convenient way to group all the mongo artefacts:

Zentradi::Document.connection
Zentradi::Document.database
Zentradi::Document.collection

The Zentradi::Document.mongo method is a short cut for setting all those at the same time:

class Post < Zentradi::Document
  mongo :database => "zentradi", :collection => "posts"

  collection.create_index "key", true # Access the collection directly, set an index.

  mongo_accessor :other_key
end

Some examples:

Post.create!(:some => :attributes)

Post.first.destroy

Post.first(:some => :attribute)

p = Post.new(some: "attributes")
p.some
p.document.some.other!.key = "hey!"
p.save
p.reload

etc…

I opted for explicit configuration of each document class. While using the Class.inherited hook might sound cool, I’m still undecided about wetter adding such magic is really worth the effort.

The Zentradi::Document#document method provide access to the “raw” mongo document, which is an instance of Hashie::Mash object (instead of a Hash) for convenience.

The mongo_accessor class method is a shortcut to access the keys of the document (Mash) from an instance of Document, but that is not really necessary.

BUT WHY?!

In brief, the [pretentious? :p] philosophy of this project is “less code is better code”.

In particular, I want:

[
  "magic",
  "ruby hooks overrides",
  "additions to the mongo driver API",
  "plugins paraphernalia",
  "use and abuse of generated methods -- find_by_blah_blah anyone? -- ",
  "features of ActiveRecord, Datamapper, [INSERT ORM HERE]"
].map do |bad_thing|
  "As little #{ bad_thing } as possible"
end

How about validations, callbacks, state machines, carbonated time bomb mirror device?

I’m afraid you’ll have to implement all those yourself if you need them. Or better yet! grab some gems!

I haven’t toyed yet with adding ActiveModel compatibility. Really, such thing is a little out of this scope of this project, although sounds like a fun thing to try on a rainy weekend :p.

DISCLAIMER

You might be interested to know, this is alpha quality software. I don’t use it myself for any production project yet. Standard disclaimers apply.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Emmanuel Oga. See LICENSE for details.