Sha256: 8d1543d24ead3707d37b2d6e507169b17d1693de33d256c6d01e5463e746f981

Contents?: true

Size: 921 Bytes

Versions: 1

Compression:

Stored size: 921 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.to_s.gsub(/(\..+)/, '.?')
      else key
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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