Module: ProxES::Helpers::Component

Defined in:
lib/proxes/helpers/component.rb

Instance Method Summary collapse

Instance Method Details

#base_pathObject



36
37
38
# File 'lib/proxes/helpers/component.rb', line 36

def base_path
  settings.base_path || "/_proxes/#{heading(:list).downcase}"
end

#datasetObject



9
10
11
# File 'lib/proxes/helpers/component.rb', line 9

def dataset
  policy_scope(settings.model_class)
end

#dehumanizedObject



32
33
34
# File 'lib/proxes/helpers/component.rb', line 32

def dehumanized
  settings.dehumanized || ActiveSupport::Inflector.underscore(heading)
end

#heading(action = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/proxes/helpers/component.rb', line 20

def heading(action = nil)
  @headings ||= begin
    heading = ActiveSupport::Inflector.demodulize settings.model_class
    h = Hash.new(heading)
    h[:new] = "New #{heading}"
    h[:list] = ActiveSupport::Inflector.pluralize heading
    h[:edit] = "Edit #{heading}"
    h
  end
  @headings[action]
end

#listObject



13
14
15
16
17
18
# File 'lib/proxes/helpers/component.rb', line 13

def list
  params['count'] ||= 10
  params['page'] ||= 1

  dataset.select.paginate(params['page'].to_i, params['count'].to_i)
end

#view_locationObject



40
41
42
# File 'lib/proxes/helpers/component.rb', line 40

def view_location
  settings.view_location || heading(:list).underscore.to_s
end