README.rdoc 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. = ORM Adapter {<img src="https://secure.travis-ci.org/ianwhite/orm_adapter.png?branch=master" alt="Build Status" />}[http://travis-ci.org/ianwhite/orm_adapter]
  2. Provides a single point of entry for popular ruby ORMs. Its target audience is gem authors who want to support more than one ORM.
  3. == Example of use
  4. require 'orm_adapter'
  5. User # is it an ActiveRecord, DM Resource, MongoMapper or MongoId Document?
  6. User.to_adapter.find_first :name => 'Fred' # we don't care!
  7. user_model = User.to_adapter
  8. user_model.get!(1) # find a record by id
  9. user_model.find_first(:name => 'fred') # find first fred
  10. user_model.find_first(:level => 'awesome', :id => 23)
  11. # find user 23, only if it's level is awesome
  12. user_model.find_all # find all users
  13. user_model.find_all(:name => 'fred') # find all freds
  14. user_model.find_all(:order => :name) # find all freds, ordered by name
  15. user_model.create!(:name => 'fred') # create a fred
  16. user_model.destroy(object) # destroy the user object
  17. @see OrmAdapter::Base for more details of the supported API
  18. == Supported ORMs
  19. Currently supported ORMs are *ActiveRecord*, *DataMapper*, *MongoMapper*, and *MongoId*.
  20. We welcome you to write new adapters as gems. ORM Adapter will stay focused in having these major ORMs working.
  21. To write an adapter look at <tt>lib/orm_adapter/adapters/active_record.rb</tt> for an example of implementation. To see how to test it, look at <tt>spec/orm_adapter/example_app_shared.rb</tt>, <tt>spec/orm_adapter/adapters/active_record_spec.rb</tt>. You'll need to require the target ORM in <tt>spec/spec_helper.rb</tt>
  22. == Goals
  23. ORM Adapter's goal is to support a minimum API used by most of the plugins that needs agnosticism beyond Active Model.
  24. ORM Adapter will support only basic methods, as +get+, +find_first+, <tt>create!</tt> and so forth. It is not ORM Adapter's goal to support different query constructions, handle table joins, etc.
  25. 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.
  26. 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.
  27. == History
  28. orm_adapter is an extraction from {pickle}[http://github.com/ianwhite/pickle] by {Ian White}[http://github.com/ianwhite]. Pickle's orm adapter included work by {Daniel Neighman}[http://github.com/hassox], {Josh Bassett}[http://github.com/nullobject], {Marc Lee}[http://github.com/maleko], and {Sebastian Zuchmanski}[http://github.com/sebcioz].
  29. {José Valim}[http://github.com/josevalim] suggested the extraction, and worked on the first release with Ian.
  30. {Luke Cunningham}[http://github.com/icaruswings] contributes the Mongo Mapper adapter.
  31. {Fred Wu}[http://github.com/fredwu] contributes the #destroy methods, and :limit, :offset options for #find_all
  32. {Tim Galeckas}[http://github.com/timgaleckas]
  33. == Development
  34. To run the specs, you can start from the last known good set of gem dependencies in Gemfile.lock.development:
  35. git clone http://github.com/ianwhite/orm_adapter
  36. cd orm_adapter
  37. cp Gemfile.lock.development Gemfile.lock
  38. bundle
  39. bundle exec rake spec
  40. == Copyright
  41. Copyright (c) 2010-2012 Ian White and José Valim. See LICENSE for details.