Sha256: 5b177f25ecfde8fee52d8ac7ad18a16e046dbe1e0fd986976ec4044adbc6cc4a
Contents?: true
Size: 1.38 KB
Versions: 270
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true module Appsignal module Utils # @api private class HashSanitizer FILTERED = "[FILTERED]".freeze class << self def sanitize(value, filter_keys = []) sanitize_value(value, filter_keys) end private def sanitize_value(value, filter_keys) case value when Hash sanitize_hash(value, filter_keys) when Array sanitize_array(value, filter_keys) when TrueClass, FalseClass, NilClass, Integer, String, Symbol, Float unmodified(value) else inspected(value) end end def sanitize_hash(source, filter_keys) {}.tap do |hash| source.each_pair do |key, value| hash[key] = if filter_keys.include?(key.to_s) FILTERED else sanitize_value(value, filter_keys) end end end end def sanitize_array(source, filter_keys) [].tap do |array| source.each_with_index do |item, index| array[index] = sanitize_value(item, filter_keys) end end end def unmodified(value) value end def inspected(value) "#<#{value.class}>" end end end end end
Version data entries
270 entries across 270 versions & 1 rubygems