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

Version Path
appsignal-3.3.11-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.11 lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.4.0-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.4.0 lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.10-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.10 lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.9-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.9 lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.8-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.8 lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.7-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.7 lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.6-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.6 lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.5-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.5 lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.4-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.4 lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.3-java lib/appsignal/utils/hash_sanitizer.rb
appsignal-3.3.3 lib/appsignal/utils/hash_sanitizer.rb