Class: SimpleRecord::Base::OrmAdapter
- Inherits:
-
OrmAdapter::Base
- Object
- OrmAdapter::Base
- SimpleRecord::Base::OrmAdapter
- Defined in:
- lib/orm_adapter-simple_record/simple_record.rb
Instance Method Summary collapse
-
#column_names ⇒ Object
get a list of column names for a given class.
- #create!(attributes = {}) ⇒ Object
- #destroy(object) ⇒ Object
- #find_all(options = {}) ⇒ Object
- #find_first(options = {}) ⇒ Object
- #get(id) ⇒ Object
- #get!(id) ⇒ Object
Instance Method Details
#column_names ⇒ Object
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
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
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
52 53 54 55 56 57 58 |
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 52 def find_all( = {}) conditions, order, limit, offset = extract_conditions!() 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
44 45 46 47 48 49 |
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 44 def find_first( = {}) conditions, order = extract_conditions!() 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
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
34 35 36 |
# File 'lib/orm_adapter-simple_record/simple_record.rb', line 34 def get!(id) klass.find(wrap_key(id)) end |