Sha256: adfdaa7f832f09418365c3cf3761b7c7a51b2057b69628f9eb8452127b94b240
Contents?: true
Size: 1.58 KB
Versions: 8
Compression:
Stored size: 1.58 KB
Contents
# frozen_string_literal: true # # helpers for core views # module CoreHelper # # Set the title for the page # def title(page_title) content_for(:title) { page_title } end # # Pull the value from system configuration and mask the ones that match the given strings # 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 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 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 def index_path "/#{controller_path}" end def model_path(model) [index_path, model.id.to_s].join('/') end def model_action_path(model, action, query = nil) [[model_path(model), action].join('/'), query&.to_query].compact.join('?') end def class_action_path(action, query = nil) [[index_path, action].join('/'), query&.to_query].compact.join('?') end def edit_model_path(model) model_action_path(model, :edit) end def current_user User.new end end
Version data entries
8 entries across 8 versions & 1 rubygems