Class OrmAdapter::Base
In: lib/orm_adapter/base.rb
Parent: Object

Methods

Attributes

klass  [R] 

Public Class methods

Your ORM adapter needs to inherit from this Base class and its adapter will be registered. To create an adapter you should create an inner constant "OrmAdapter" e.g. ActiveRecord::Base::OrmAdapter

@see orm_adapters/active_record @see orm_adapters/datamapper @see orm_adapters/mongoid

Public Instance methods

Get a list of column/property/field names

Create a model using attributes

Destroy an instance by passing in the instance itself.

Find all models, optionally matching conditions, and specifying order @see OrmAdapter::Base#find_first for how to specify order and conditions

Find the first instance, optionally matching conditions, and specifying order

You can call with just conditions, providing a hash

  User.to_adapter.find_first :name => "Fred", :age => 23

Or you can specify :order, and :conditions as keys

  User.to_adapter.find_first :conditions => {:name => "Fred", :age => 23}
  User.to_adapter.find_first :order => [:age, :desc]
  User.to_adapter.find_first :order => :name, :conditions => {:age => 18}

When specifying :order, it may be

  • a single arg e.g. :order => :name
  • a single pair with :asc, or :desc as last, e.g. :order => [:name, :desc]
  • an array of single args or pairs (with :asc or :desc as last), e.g. :order => [[:name, :asc], [:age, :desc]]

Get an instance by id of the model. Returns nil if a model is not found. This should comply with ActiveModel#to_key API, i.e.:

  User.to_adapter.get(@user.to_key) == @user

Get an instance by id of the model. Raises an error if a model is not found. This should comply with ActiveModel#to_key API, i.e.:

  User.to_adapter.get!(@user.to_key) == @user

Protected Instance methods

given an options hash, with optional :conditions, :order, :limit and :offset keys, returns conditions, normalized order, limit and offset

given an order argument, returns an array of pairs, with each pair containing the attribute, and :asc or :desc

[Validate]