Sha256: 5e9c1bc66618fcf1bb833b909a5f91eb13a35538d42090e6cde24510d9526131

Contents?: true

Size: 916 Bytes

Versions: 1

Compression:

Stored size: 916 Bytes

Contents

module Appsignal
  module Utils
    def self.sanitize(params, only_top_level=false, key_sanitizer=nil)
      if params.is_a?(Hash)
        {}.tap do |hsh|
          params.each do |key, val|
            hsh[self.sanitize_key(key, key_sanitizer)] = if only_top_level
              '?'
            else
              sanitize(val, only_top_level, key_sanitizer=nil)
            end
          end
        end
      elsif params.is_a?(Array)
        if only_top_level
          sanitize(params[0], only_top_level, key_sanitizer=nil)
        elsif params.first.is_a?(String)
          ['?']
        else
          params.map do |item|
            sanitize(item, only_top_level, key_sanitizer=nil)
          end
        end
      else
        '?'
      end
    end

    def self.sanitize_key(key, sanitizer)
      case sanitizer
      when :mongodb then key.gsub(/(\..+)/, '.?')
      else key
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appsignal-1.0.5.beta.1 lib/appsignal/utils.rb