12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/tensorbuzz/api/sanitizer.rb', line 12
def self.call(value, depth: 0, key: nil)
return '[redacted]' if key.to_s.match?(SENSITIVE_KEY)
return '[maximum depth reached]' if depth >= MAX_DEPTH
case value
when Array
value.first(MAX_ARRAY_LENGTH).map { |item| call(item, depth: depth + 1) }
when Hash
value.first(MAX_HASH_KEYS).to_h do |child_key, child_value|
[child_key.to_s, call(child_value, depth: depth + 1, key: child_key)]
end
when String
truncate(value)
when Numeric, TrueClass, FalseClass, NilClass
value
else
truncate(value.to_s)
end
end
|