Class: Smartsheet::API::Censor
- Inherits:
-
Object
- Object
- Smartsheet::API::Censor
- Defined in:
- lib/smartsheet/api/request_logger.rb
Overview
Censors strings and hash values for select blacklisted keys
Constant Summary collapse
- EXPOSED_CHARS =
4
- KEY_TO_STRING =
->(k){ k.to_s }
- KEY_TO_DOWNCASE_STRING =
->(k){ k.to_s.downcase }
Instance Method Summary collapse
- #censor(str) ⇒ Object
- #censor_hash(h, case_insensitive: false) ⇒ Object
-
#initialize(*blacklist) ⇒ Censor
constructor
A new instance of Censor.
Constructor Details
#initialize(*blacklist) ⇒ Censor
Returns a new instance of Censor.
11 12 13 |
# File 'lib/smartsheet/api/request_logger.rb', line 11 def initialize(*blacklist) @blacklist = Set.new(blacklist) end |
Instance Method Details
#censor(str) ⇒ Object
23 24 25 26 27 |
# File 'lib/smartsheet/api/request_logger.rb', line 23 def censor(str) total_length = str.length censored_length = [total_length - EXPOSED_CHARS, 0].max ('*' * censored_length) + str[censored_length...total_length] end |
#censor_hash(h, case_insensitive: false) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/smartsheet/api/request_logger.rb', line 15 def censor_hash(h, case_insensitive: false) if case_insensitive _censor_hash(h, KEY_TO_DOWNCASE_STRING, downcased_blacklist) else _censor_hash(h, KEY_TO_STRING, blacklist) end end |