Module: ProxES::Helpers::Component

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

Instance Method Summary collapse

Instance Method Details

#base_pathObject



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

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

#datasetObject



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

def dataset
  policy_scope(settings.model_class)
end

#dehumanizedObject



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

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

#heading(action = nil) ⇒ Object



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

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



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

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

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

#view_locationObject



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

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