Module: Trestle::Adapters::SequelAdapter
- Defined in:
- lib/trestle/adapters/sequel_adapter.rb
Instance Method Summary collapse
- #build_instance(attrs = {}, params = {}) ⇒ Object
- #collection(params = {}) ⇒ Object
- #count(collection) ⇒ Object
- #default_form_attributes ⇒ Object
- #default_table_attributes ⇒ Object
- #delete_instance(instance, params = {}) ⇒ Object
- #find_instance(params) ⇒ Object
- #merge_scopes(scope, other) ⇒ Object
- #save_instance(instance, params = {}) ⇒ Object
- #sort(collection, field, order) ⇒ Object
- #update_instance(instance, attrs, params = {}) ⇒ Object
Instance Method Details
#build_instance(attrs = {}, params = {}) ⇒ Object
21 22 23 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 21 def build_instance(attrs={}, params={}) model.new(attrs) end |
#collection(params = {}) ⇒ Object
13 14 15 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 13 def collection(params={}) model.dataset end |
#count(collection) ⇒ Object
41 42 43 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 41 def count(collection) collection.count end |
#default_form_attributes ⇒ Object
55 56 57 58 59 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 55 def default_form_attributes default_attributes.reject do |attribute| primary_key?(attribute) || inheritance_column?(attribute) end end |
#default_table_attributes ⇒ Object
49 50 51 52 53 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 49 def default_table_attributes default_attributes.reject do |attribute| inheritance_column?(attribute) end end |
#delete_instance(instance, params = {}) ⇒ Object
33 34 35 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 33 def delete_instance(instance, params={}) instance.destroy end |
#find_instance(params) ⇒ Object
17 18 19 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 17 def find_instance(params) model[params[:id]] end |
#merge_scopes(scope, other) ⇒ Object
37 38 39 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 37 def merge_scopes(scope, other) scope.intersect(other) end |
#save_instance(instance, params = {}) ⇒ Object
29 30 31 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 29 def save_instance(instance, params={}) instance.save end |
#sort(collection, field, order) ⇒ Object
45 46 47 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 45 def sort(collection, field, order) collection.order(Sequel.send(order, field)) end |
#update_instance(instance, attrs, params = {}) ⇒ Object
25 26 27 |
# File 'lib/trestle/adapters/sequel_adapter.rb', line 25 def update_instance(instance, attrs, params={}) instance.set(attrs) end |