Module: CoreHelper
- Defined in:
- app/helpers/core_helper.rb
Overview
helpers for core views
Instance Method Summary collapse
- #class_action_path(action, query = nil) ⇒ Object
- #current_user ⇒ Object
- #edit_model_path(model) ⇒ Object
- #index_path ⇒ Object
-
#mask_system_configuration(field) ⇒ Object
Pull the value from system configuration and mask the ones that match the given strings.
-
#mask_value(value, default: '************') ⇒ Object
Mask a value, i.e.
- #model_action_path(model, action, query = nil) ⇒ Object
- #model_path(model) ⇒ Object
-
#title(page_title) ⇒ Object
Set the title for the page.
Instance Method Details
#class_action_path(action, query = nil) ⇒ Object
57 58 59 |
# File 'app/helpers/core_helper.rb', line 57 def class_action_path(action, query = nil) [[index_path, action].join('/'), query&.to_query].compact.join('?') end |
#current_user ⇒ Object
65 66 67 |
# File 'app/helpers/core_helper.rb', line 65 def current_user @current_user || User.new end |
#edit_model_path(model) ⇒ Object
61 62 63 |
# File 'app/helpers/core_helper.rb', line 61 def edit_model_path(model) model_action_path(model, :edit) end |
#index_path ⇒ Object
45 46 47 |
# File 'app/helpers/core_helper.rb', line 45 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
17 18 19 20 21 22 23 24 |
# File 'app/helpers/core_helper.rb', line 17 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
-
If blank or nil, return the default
-
Length of 1-4 only show the first character
-
Length 5-10 only show the first and last character
-
Otherwise show the first and last three characters
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/core_helper.rb', line 32 def mask_value(value, default: '************') return default if value.blank? case value.length when 1..4 "#{value.first}***********" when 5..10 "#{value.first}**********#{value.last}" else "#{value[0..2]}**********#{value[-3..-1]}" end end |
#model_action_path(model, action, query = nil) ⇒ Object
53 54 55 |
# File 'app/helpers/core_helper.rb', line 53 def model_action_path(model, action, query = nil) [[model_path(model), action].join('/'), query&.to_query].compact.join('?') end |
#model_path(model) ⇒ Object
49 50 51 |
# File 'app/helpers/core_helper.rb', line 49 def model_path(model) [index_path, model.id.to_s].join('/') 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 |