class SexySettings::SensitiveDataProtector
This class holds logic sensitive data hiding
Constants
- PROTECTED_PROPERTIES
- URL_REGEXP
Attributes
prop[R]
value[R]
Public Class Methods
new(prop, value)
click to toggle source
# File lib/sexy_settings/sensitive_data_protector.rb, line 8 def initialize(prop, value) @prop = prop @value = value.to_s end
Public Instance Methods
hide_protected_data(value)
click to toggle source
# File lib/sexy_settings/sensitive_data_protector.rb, line 19 def hide_protected_data(value) return value if value.nil? return '********' if value.to_s.size <= 4 "********#{value.to_s[-4..-1]}" end
hide_protected_data_in_url(value)
click to toggle source
# File lib/sexy_settings/sensitive_data_protector.rb, line 25 def hide_protected_data_in_url(value) return value if value.nil? || URL_REGEXP !~ value userpass = URL_REGEXP.match(value)[:userpass] return value if userpass.nil? || userpass.empty? value.sub(userpass, protected_userpass(userpass)) end
protected_userpass(value)
click to toggle source
# File lib/sexy_settings/sensitive_data_protector.rb, line 32 def protected_userpass(value) value.split(':', 2).compact.map(&method(:hide_protected_data)).join(':') end
protected_value()
click to toggle source
# File lib/sexy_settings/sensitive_data_protector.rb, line 13 def protected_value return hide_protected_data_in_url(value) if /_url\z/ =~ prop return value unless PROTECTED_PROPERTIES.any? { |el| el =~ prop } hide_protected_data(value) end