Module: CoreHelper

Defined in:
app/helpers/core_helper.rb

Overview

helpers for core views

Instance Method Summary collapse

Instance Method Details

Set the bread crumbs for navigation



24
25
26
# File 'app/helpers/core_helper.rb', line 24

def breadcrumbs(&block)
  content_for(:breadcrumb_content) { block }
end

#class_action_path(action, query = nil) ⇒ Object



88
89
90
# File 'app/helpers/core_helper.rb', line 88

def class_action_path(action, query = nil)
  [[index_path, action].join('/'), query&.to_query].compact.join('?')
end

#edit_model_path(model) ⇒ Object



92
93
94
# File 'app/helpers/core_helper.rb', line 92

def edit_model_path(model)
  model_action_path(model, :edit)
end

#flash_map_name(key) ⇒ Object

Map alerts to a valid icon



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/core_helper.rb', line 31

def flash_map_name(key)
  case key
  when 'alert'
    'notification_important'
  when 'success'
    'check_circle'
  when 'notice'
    'note'
  else
    key
  end
end

#index_pathObject



76
77
78
# File 'app/helpers/core_helper.rb', line 76

def index_path
  "/#{controller_path}"
end

#mask_system_configuration(field) ⇒ Object

Pull the value from system configuration and mask the ones that match the given strings



47
48
49
50
51
52
53
54
# File 'app/helpers/core_helper.rb', line 47

def mask_system_configuration(field)
  should_mask = false
  %w[password token secret access_key api_key].each do |mask|
    should_mask |= field.include?(mask)
  end
  value = SystemConfiguration.send(field)
  should_mask ? mask_value(value, default: 'Not Set') : value
end

#mask_value(value, default: '************') ⇒ Object

Mask a value, i.e. password field

  1. If blank or nil, return the default

  2. Length of 1-4 only show the first character

  3. Length 5-10 only show the first and last character

  4. Otherwise show the first and last three characters



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/core_helper.rb', line 62

def mask_value(value, default: '************')
  return default if value.blank? || !value.respond_to?(:to_s)

  string_value = value.to_s
  case string_value.length
  when 1..4
    "#{string_value.first}***********"
  when 5..10
    "#{string_value.first}**********#{string_value.last}"
  else
    "#{string_value[0..2]}**********#{string_value[-3..]}"
  end
end

#model_action_path(model, action, query = nil) ⇒ Object



84
85
86
# File 'app/helpers/core_helper.rb', line 84

def model_action_path(model, action, query = nil)
  [[model_path(model), action].join('/'), query&.to_query].compact.join('?')
end

#model_path(model) ⇒ Object



80
81
82
# File 'app/helpers/core_helper.rb', line 80

def model_path(model)
  [index_path, model.id.to_s].join('/')
end

#search_url(search_url) ⇒ Object

Record the search url if one is needed



17
18
19
# File 'app/helpers/core_helper.rb', line 17

def search_url(search_url)
  content_for(:search_url) { search_url }
end

#title(page_title) ⇒ Object

Set the title for the page



10
11
12
# File 'app/helpers/core_helper.rb', line 10

def title(page_title)
  content_for(:title) { page_title }
end