Module: Trestle::Adapters::ActiveRecordAdapter

Defined in:
lib/trestle/adapters/active_record_adapter.rb

Instance Method Summary collapse

Instance Method Details

#build_instance(attrs = {}, params = {}) ⇒ Object



12
13
14
# File 'lib/trestle/adapters/active_record_adapter.rb', line 12

def build_instance(attrs={}, params={})
  model.new(attrs)
end

#collection(params = {}) ⇒ Object



4
5
6
# File 'lib/trestle/adapters/active_record_adapter.rb', line 4

def collection(params={})
  model.all
end

#count(collection) ⇒ Object



32
33
34
# File 'lib/trestle/adapters/active_record_adapter.rb', line 32

def count(collection)
  collection.count(:all)
end

#default_form_attributesObject



50
51
52
53
54
# File 'lib/trestle/adapters/active_record_adapter.rb', line 50

def default_form_attributes
  default_attributes.reject do |attribute|
    primary_key?(attribute) || inheritance_column?(attribute) || counter_cache_column?(attribute)
  end
end

#default_table_attributesObject



44
45
46
47
48
# File 'lib/trestle/adapters/active_record_adapter.rb', line 44

def default_table_attributes
  default_attributes.reject do |attribute|
    inheritance_column?(attribute) || counter_cache_column?(attribute)
  end
end

#delete_instance(instance, params = {}) ⇒ Object



24
25
26
# File 'lib/trestle/adapters/active_record_adapter.rb', line 24

def delete_instance(instance, params={})
  instance.destroy
end

#find_instance(params) ⇒ Object



8
9
10
# File 'lib/trestle/adapters/active_record_adapter.rb', line 8

def find_instance(params)
  model.find(params[:id])
end

#human_attribute_name(attribute, options = {}) ⇒ Object



40
41
42
# File 'lib/trestle/adapters/active_record_adapter.rb', line 40

def human_attribute_name(attribute, options={})
  model.human_attribute_name(attribute, options)
end

#merge_scopes(scope, other) ⇒ Object



28
29
30
# File 'lib/trestle/adapters/active_record_adapter.rb', line 28

def merge_scopes(scope, other)
  scope.merge(other)
end

#save_instance(instance, params = {}) ⇒ Object



20
21
22
# File 'lib/trestle/adapters/active_record_adapter.rb', line 20

def save_instance(instance, params={})
  instance.save
end

#sort(collection, field, order) ⇒ Object



36
37
38
# File 'lib/trestle/adapters/active_record_adapter.rb', line 36

def sort(collection, field, order)
  collection.reorder(field => order)
end

#update_instance(instance, attrs, params = {}) ⇒ Object



16
17
18
# File 'lib/trestle/adapters/active_record_adapter.rb', line 16

def update_instance(instance, attrs, params={})
  instance.assign_attributes(attrs)
end