Class: Her::Model::OrmAdapter
- Inherits:
-
OrmAdapter::Base
- Object
- OrmAdapter::Base
- Her::Model::OrmAdapter
- Defined in:
- lib/her_extension/her_orm_adapter.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
17 18 19 |
# File 'lib/her_extension/her_orm_adapter.rb', line 17 def column_names @columns ||= klass.instance_methods.grep(/_will_change!$/).map { |e| e.to_s.gsub('_will_change!','') } end |
#create!(attributes = {}) ⇒ Object
44 45 46 |
# File 'lib/her_extension/her_orm_adapter.rb', line 44 def create!(attributes = {}) klass.create!(attributes) end |
#destroy(object) ⇒ Object
49 50 51 |
# File 'lib/her_extension/her_orm_adapter.rb', line 49 def destroy(object) object.destroy if valid_object?(object) end |
#find_all(options = {}) ⇒ Object
39 40 41 |
# File 'lib/her_extension/her_orm_adapter.rb', line 39 def find_all( = {}) klass.where() end |
#find_first(options = {}) ⇒ Object
34 35 36 |
# File 'lib/her_extension/her_orm_adapter.rb', line 34 def find_first( = {}) klass.where().limit(1).first end |
#get(id) ⇒ Object
29 30 31 |
# File 'lib/her_extension/her_orm_adapter.rb', line 29 def get(id) klass.find(wrap_key(id)) end |
#get!(id) ⇒ Object
22 23 24 25 26 |
# File 'lib/her_extension/her_orm_adapter.rb', line 22 def get!(id) res = klass.find(wrap_key(id)) raise Her::Errors::ResourceNotFound, "resource not found" unless res res end |