Class: Trestle::Resource::Builder

Inherits:
Admin::Builder show all
Defined in:
lib/trestle/resource/builder.rb

Instance Method Summary collapse

Methods inherited from Admin::Builder

#admin, #breadcrumb, #controller, create, #form, #hook, #initialize, #menu, #routes, #table

Methods inherited from Builder

#build, build, target

Constructor Details

This class inherits a constructor from Trestle::Admin::Builder

Instance Method Details

#adapter(&block) ⇒ Object


7
8
9
10
11
# File 'lib/trestle/resource/builder.rb', line 7

def adapter(&block)
  klass = admin.adapter_class
  klass.class_eval(&block) if block_given?
  klass
end

#adapter=(adapter) ⇒ Object


13
14
15
# File 'lib/trestle/resource/builder.rb', line 13

def adapter=(adapter)
  admin.adapter_class = adapter
end

#build_instance(&block) ⇒ Object


33
34
35
# File 'lib/trestle/resource/builder.rb', line 33

def build_instance(&block)
  admin.define_adapter_method(:build_instance, &block)
end

#collection(&block) ⇒ Object


24
25
26
# File 'lib/trestle/resource/builder.rb', line 24

def collection(&block)
  admin.define_adapter_method(:collection, &block)
end

#count(&block) ⇒ Object


82
83
84
# File 'lib/trestle/resource/builder.rb', line 82

def count(&block)
  admin.define_adapter_method(:count, &block)
end

#decorate_collection(&block) ⇒ Object


61
62
63
# File 'lib/trestle/resource/builder.rb', line 61

def decorate_collection(&block)
  admin.define_adapter_method(:decorate_collection, &block)
end

#decorator(decorator) ⇒ Object


57
58
59
# File 'lib/trestle/resource/builder.rb', line 57

def decorator(decorator)
  admin.decorator = decorator
end

#delete_instance(&block) ⇒ Object


45
46
47
# File 'lib/trestle/resource/builder.rb', line 45

def delete_instance(&block)
  admin.define_adapter_method(:delete_instance, &block)
end

#find_instance(&block) ⇒ Object Also known as: instance


28
29
30
# File 'lib/trestle/resource/builder.rb', line 28

def find_instance(&block)
  admin.define_adapter_method(:find_instance, &block)
end

#merge_scopes(&block) ⇒ Object


65
66
67
# File 'lib/trestle/resource/builder.rb', line 65

def merge_scopes(&block)
  admin.define_adapter_method(:merge_scopes, &block)
end

#paginate(options = {}, &block) ⇒ Object


77
78
79
80
# File 'lib/trestle/resource/builder.rb', line 77

def paginate(options={}, &block)
  admin.pagination_options = admin.pagination_options.merge(options)
  admin.define_adapter_method(:paginate, &block)
end

#params(&block) ⇒ Object


53
54
55
# File 'lib/trestle/resource/builder.rb', line 53

def params(&block)
  admin.define_adapter_method(:permitted_params, &block)
end

#remove_action(*actions) ⇒ Object


17
18
19
20
21
22
# File 'lib/trestle/resource/builder.rb', line 17

def remove_action(*actions)
  actions.each do |action|
    controller.remove_possible_method(action.to_sym)
    admin.actions.delete(action.to_sym)
  end
end

#return_to(options = {}, &block) ⇒ Object


97
98
99
100
101
102
103
# File 'lib/trestle/resource/builder.rb', line 97

def return_to(options={}, &block)
  actions = options.key?(:on) ? Array(options[:on]) : [:create, :update, :destroy]

  actions.each do |action|
    admin.return_locations[action.to_sym] = block
  end
end

#save_instance(&block) ⇒ Object


41
42
43
# File 'lib/trestle/resource/builder.rb', line 41

def save_instance(&block)
  admin.define_adapter_method(:save_instance, &block)
end

#scope(name, scope = nil, options = {}, &block) ⇒ Object


91
92
93
94
95
# File 'lib/trestle/resource/builder.rb', line 91

def scope(name, scope=nil, options={}, &block)
  scopes do
    scope(name, scope, options, &block)
  end
end

#scopes(options = {}, &block) ⇒ Object


86
87
88
89
# File 'lib/trestle/resource/builder.rb', line 86

def scopes(options={}, &block)
  admin.scopes.options.merge!(options)
  admin.scopes.append(&block) if block_given?
end

#sort(&block) ⇒ Object


69
70
71
# File 'lib/trestle/resource/builder.rb', line 69

def sort(&block)
  admin.define_adapter_method(:sort, &block)
end

#sort_column(column, &block) ⇒ Object


73
74
75
# File 'lib/trestle/resource/builder.rb', line 73

def sort_column(column, &block)
  admin.column_sorts[column.to_sym] = block
end

#to_param(&block) ⇒ Object


49
50
51
# File 'lib/trestle/resource/builder.rb', line 49

def to_param(&block)
  admin.define_adapter_method(:to_param, &block)
end

#update_instance(&block) ⇒ Object


37
38
39
# File 'lib/trestle/resource/builder.rb', line 37

def update_instance(&block)
  admin.define_adapter_method(:update_instance, &block)
end