Class: SimpleRecord::Base::OrmAdapter

Inherits:
OrmAdapter::Base
  • Object
show all
Defined in:
lib/orm_adapter-simple_record/simple_record.rb

Instance Method Summary collapse

Instance Method Details

#column_namesObject

get a list of column names for a given class



29
30
31
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 29

def column_names
  klass.defined_attributes.keys
end

#create!(attributes = {}) ⇒ Object

Raises:

  • (SimpleRecordError)

See Also:

  • OrmAdapter::Base#create!


61
62
63
64
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 61

def create!(attributes = {})
  raise SimpleRecordError.new if attributes.keys.find{|k| !self.column_names.include?(k) }
  klass.create! attributes
end

#destroy(object) ⇒ Object

See Also:

  • OrmAdapter::Base#destroy


67
68
69
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 67

def destroy(object)
  object.destroy && object if valid_object?(object)
end

#find_all(options = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_all


52
53
54
55
56
57
58
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 52

def find_all(options = {})
  conditions, order, limit, offset = extract_conditions!(options)
  params = { :conditions => conditions_to_array(conditions_to_fields(conditions)) }
  params[:order] = order_clause(order) unless order && order.empty?
  params[:limit] = limit unless limit.nil?
  klass.find(:all, params)
end

#find_first(options = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_first


44
45
46
47
48
49
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 44

def find_first(options = {})
  conditions, order = extract_conditions!(options)
  params = { :conditions => conditions_to_array(conditions_to_fields(conditions)) }
  params[:order] = order_clause(order) unless order && order.empty?
  klass.find(:first, params)
end

#get(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get


39
40
41
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 39

def get(id)
  klass.find(:first, :id => wrap_key(id))
end

#get!(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get!


34
35
36
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 34

def get!(id)
  klass.find(wrap_key(id))
end