• Stars
    star
    194
  • Rank 200,219 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 14 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Provides a single point of entry for using basic features of ruby ORMs

ORM Adapter <img src=“https://secure.travis-ci.org/ianwhite/orm_adapter.png?branch=master” alt=“Build Status” />

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, MongoMapper 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_first(:level => 'awesome', :id => 23)
                                        # find user 23, only if it's level is awesome
user_model.find_all                     # find all users
user_model.find_all(:name => 'fred')    # find all freds
user_model.find_all(:order => :name)    # find all freds, ordered by name
user_model.create!(:name => 'fred')     # create a fred
user_model.destroy(object)              # destroy the user object

@see OrmAdapter::Base for more details of the supported API

Supported ORMs

Currently supported ORMs are ActiveRecord, DataMapper, MongoMapper, and MongoId.

We welcome you to write new adapters as gems. ORM Adapter will stay focused in having these major ORMs working. Other adapters will be named orm_adapter-somedatabase, you can find the ones available on rubygems.

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

Goals

ORM Adapter’s 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.

ORM adapter provides a consistent API for these basic class or ‘factory’ methods. It does not attempt to unify the behaviour of model instances returned by these methods. This means that unifying the behaviour of methods such as ‘model.save`, and `model.valid?` is beyond the scope of orm_adapter.

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.

History

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.

Luke Cunningham contributes the Mongo Mapper adapter.

Fred Wu contributes the #destroy methods, and :limit, :offset options for #find_all

Tim Galeckas

Development

To run the specs, you can start from the last known good set of gem dependencies in Gemfile.lock.development:

git clone http://github.com/ianwhite/orm_adapter
cd orm_adapter
bundle install
bundle exec rake spec

To run specs for different versions of ORMs, you can specify a gemfile from the ‘gemfiles` directory, e.g.

BUNDLE_GEMFILE=gemfiles/activerecord-4.1.gemfile bundle install
BUNDLE_GEMFILE=gemfiles/activerecord-4.1.gemfile bundle exec rake spec

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

More Repositories

1

pickle

Easy model creation/reference in cucumber - optionally leveraging your factories/blueprints
Ruby
510
star
2

nested_has_many_through

rails plugin that allows has_many :through to go through other has_many :throughs
Ruby
143
star
3

resources_controller

resources_controller rails plugin: rc makes RESTful controllers fun
Ruby
79
star
4

truncate_html

rails helper that works just like truncate, but it respects, and produces well formed html
Ruby
63
star
5

garlic

garlic is a set of commands/rake tasks to help with CI across multiple rails/dependency versions
Ruby
34
star
6

inherit_views

rails plugin that enables inheritance of views along a controller class heirachy
Ruby
29
star
7

wac

Wolfram|Alpha client
Ruby
21
star
8

response_for

response for lets you decorate your actions respond_to blocks
Ruby
16
star
9

webrat_extra_steps

generator that parses your existing webrat steps to create some extra ones
Ruby
10
star
10

matewatch

Simple time tracking for textmate users
9
star
11

response_for_rc

Set of resourceful actions written in the response_for style for resources_controller
Ruby
9
star
12

git_friendly_dumper

Rails plugin that creates a dump directory with one file per record - much friendlier for git
Ruby
5
star
13

rc

resources_controller rewrite
Ruby
4
star
14

rspec-dev

Resources for rspec developers/contributors
Ruby
3
star
15

clag

Clag - not in active development - use machinist or factory_girl
Ruby
3
star
16

subit

Simple regexp based text substitution parser, with support for multiple rulesets, and in-place replacement
Ruby
3
star
17

clock_time

Adds Time.tomorrow, Time.yesterday, and instance methods like time.at_2am, time.at_0200
Ruby
3
star
18

handbrake-batch-convert.rb

Simple ruby script to batch convert using handbrake's cli
Ruby
2
star
19

dotfiles

My dotfiles
Shell
2
star
20

visit

Simple ruby visitor
1
star