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, #remove_action, #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



26
27
28
# File 'lib/trestle/resource/builder.rb', line 26

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

#collection(&block) ⇒ Object



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

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

#count(&block) ⇒ Object



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

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

#decorate_collection(&block) ⇒ Object



55
56
57
# File 'lib/trestle/resource/builder.rb', line 55

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

#decorator(decorator) ⇒ Object



51
52
53
# File 'lib/trestle/resource/builder.rb', line 51

def decorator(decorator)
  admin.decorator = decorator
end

#delete_instance(&block) ⇒ Object



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

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

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



21
22
23
# File 'lib/trestle/resource/builder.rb', line 21

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

#merge_scopes(&block) ⇒ Object



59
60
61
# File 'lib/trestle/resource/builder.rb', line 59

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

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



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

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

#permitted_params(&block) ⇒ Object Also known as: params



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

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

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



93
94
95
96
97
98
99
# File 'lib/trestle/resource/builder.rb', line 93

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



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

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

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



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

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

#scopes(defaults: {}, **options, &block) ⇒ Object



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

def scopes(defaults: {}, **options, &block)
  defaults = defaults.merge(options.slice(:count))

  admin.scopes.apply_options!(options)
  admin.scopes.append(**defaults, &block) if block_given?
end

#sort(&block) ⇒ Object



63
64
65
# File 'lib/trestle/resource/builder.rb', line 63

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

#sort_column(column, &block) ⇒ Object



67
68
69
# File 'lib/trestle/resource/builder.rb', line 67

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

#to_param(&block) ⇒ Object



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

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

#update_instance(&block) ⇒ Object



30
31
32
# File 'lib/trestle/resource/builder.rb', line 30

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