class Her::Model::OrmAdapter

Public Instance Methods

column_names() click to toggle source

Get a list of column/property/field names

# File lib/orm_adapter/her/adapter.rb, line 23
def column_names
  klass.model_attributes
end
create!(attributes = {}) click to toggle source

Create a model using attributes

# File lib/orm_adapter/her/adapter.rb, line 75
def create!(attributes = {})
  klass.create(attributes)
end
destroy(object) click to toggle source

Destroy an instance by passing in the instance itself.

# File lib/orm_adapter/her/adapter.rb, line 80
def destroy(object)
  object.destroy if valid_object?(object)
end
find_all(options = {}) click to toggle source

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

# File lib/orm_adapter/her/adapter.rb, line 69
def find_all(options = {})
  conditions, order = extract_conditions!(options)
  klass.where(conditions).all
end
find_first(options = {}) click to toggle source

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]]

# File lib/orm_adapter/her/adapter.rb, line 62
def find_first(options = {})
  conditions, order = extract_conditions!(options)
  klass.where(conditions).first
end
get(id) click to toggle source

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
# File lib/orm_adapter/her/adapter.rb, line 41
def get(id)
  klass.find(klass.primary_key => wrap_key(id))
end
get!(id) click to toggle source

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
# File lib/orm_adapter/her/adapter.rb, line 32
def get!(id)
  klass.find(klass.primary_key => wrap_key(id)) || raise(ArgumentError, "#{klass.name} not found with #{klass.primary_key} of #{wrap_key(id)}")
end