class OrmAdapter::Base
def self.inherited(adapter)
- See: orm_adapters/mongoid -
See: orm_adapters/datamapper -
See: orm_adapters/active_record -
def self.inherited(adapter) OrmAdapter.adapters << adapter super end
def column_names
def column_names raise NotSupportedError end
def create!(attributes = {})
def create!(attributes = {}) raise NotSupportedError end
def destroy(object)
def destroy(object) raise NotSupportedError end
def extract_conditions!(options = {})
with optional :conditions, :order, :limit and :offset keys,
given an options hash,
def extract_conditions!(options = {}) order = normalize_order(options.delete(:order)) limit = options.delete(:limit) offset = options.delete(:offset) conditions = options.delete(:conditions) || options [conditions, order, limit, offset] end
def find_all(options = {})
- See: OrmAdapter::Base#find_first - for how to specify order and conditions
def find_all(options = {}) raise NotSupportedError end
def find_first(options = {})
* an array of single args or pairs (with :asc or :desc as last), e.g. :order => [[:name, :asc], [:age, :desc]]
* a single pair with :asc, or :desc as last, e.g. :order => [:name, :desc]
* a single arg e.g. :order => :name
When specifying :order, it may be
User.to_adapter.find_first :order => :name, :conditions => {:age => 18}
User.to_adapter.find_first :order => [:age, :desc]
User.to_adapter.find_first :conditions => {:name => "Fred", :age => 23}
Or you can specify :order, and :conditions as keys
User.to_adapter.find_first :name => "Fred", :age => 23
You can call with just conditions, providing a hash
Find the first instance, optionally matching conditions, and specifying order
def find_first(options = {}) raise NotSupportedError end
def get(id)
User.to_adapter.get(@user.to_key) == @user
This should comply with ActiveModel#to_key API, i.e.:
Get an instance by id of the model. Returns nil if a model is not found.
def get(id) raise NotSupportedError end
def get!(id)
User.to_adapter.get!(@user.to_key) == @user
This should comply with ActiveModel#to_key API, i.e.:
Get an instance by id of the model. Raises an error if a model is not found.
def get!(id) raise NotSupportedError end
def initialize(klass)
def initialize(klass) @klass = klass end
def normalize_order(order)
def normalize_order(order) order = Array(order) if order.length == 2 && !order[0].is_a?(Array) && [:asc, :desc].include?(order[1]) order = [order] else order = order.map {|pair| pair.is_a?(Array) ? pair : [pair, :asc] } end order.each do |pair| pair.length == 2 or raise ArgumentError, "each order clause must be a pair (unknown clause #{pair.inspect})" [:asc, :desc].include?(pair[1]) or raise ArgumentError, "order must be specified with :asc or :desc (unknown key #{pair[1].inspect})" end order end
def valid_object?(object)
def valid_object?(object) object.class == klass end
def wrap_key(key)
def wrap_key(key) key.is_a?(Array) ? key.first : key end