Provides a single point of entry for using basic features of ruby ORMs
Switch branches/tags
Clone or download
Pull request Compare This branch is even with 28clouds:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


ORM Adapter

Provides a single point of entry for popular ruby ORMs. Its target audience is gem authors who want to support more than one ORM.

Example of use

require 'orm_adapter'

User # is it an ActiveRecord, DM Resource, or MongoId Document?

User.to_adapter.find_first :name => 'Fred' # we don't care!

user_model = User.to_adapter
user_model.get!(1)                      # find a record by id
user_model.find_first(:name => 'fred')  # find first fred
user_model.find_all(:name => 'fred')    # find all freds
user_model.create!(:name => 'fred')     # create a fred

Supported ORMs

Currently supported ORMs are ActiveRecord, DataMapper and MongoId.

We welcome you to write new adapters as gems. ORM Adapter will stay focused in having these three major ORMs working.

To write an adapter look at lib/orm_adapter/adapters/active_record.rb for an example of implementation. To see how to test it, look at spec/orm_adapter/example_app_shared.rb, spec/orm_adapter/adapters/active_record_spec.rb. You'll need to require the target ORM in spec/spec_helper.rb


ORM Adapter goal is to support a minimum API used by most of the plugins that needs agnosticism beyond Active Model.

ORM Adapter will support only basic methods, as get, find_first, create! and so forth. It is not ORM Adapter's goal to support different query constructions, handle table joins, etc.

If you need complex queries, we recommend you to subclass ORM Adapters in your plugin and extend it expressing these query conditions as part of your domain logic.


orm_adapter is an extraction from pickle by Ian White. Pickle's orm adapter included work by Daniel Neighman, Josh Bassett, Marc Lee, and Sebastian Zuchmanski.

José Valim suggested the extraction, and worked on the first release with Ian.


Copyright © 2010 Ian White and José Valim. See LICENSE for details.