class InfluxReporter::Filter

@api private

Constants

MASK

Attributes

config[R]

Public Class Methods

new(config) click to toggle source
# File lib/influx_reporter/filter.rb, line 8
def initialize(config)
  @config = config
  @params = rails_filters || config.filter_parameters
end

Public Instance Methods

apply(data, _opts = {}) click to toggle source
# File lib/influx_reporter/filter.rb, line 15
def apply(data, _opts = {})
  case data
    when String
      apply_to_string data, opts = {}
    when Hash
      apply_to_hash data
  end
end
apply_to_hash(hsh) click to toggle source
# File lib/influx_reporter/filter.rb, line 34
def apply_to_hash(hsh)
  hsh.each_with_object({}) do |kv, filtered|
    key, value = kv
    filtered[key] = sanitize(key, value)
  end
end
apply_to_string(str, opts = {}) click to toggle source
# File lib/influx_reporter/filter.rb, line 24
def apply_to_string(str, opts = {})
  sep = opts[:separator] || '&'
  kv_sep = opts[:kv_separator] || '='

  str.split(sep).map do |kv|
    key, value = kv.split(kv_sep)
    [key, kv_sep, sanitize(key, value)].join
  end.join(sep)
end
sanitize(key, value) click to toggle source
# File lib/influx_reporter/filter.rb, line 41
def sanitize(key, value)
  should_filter?(key) ? MASK : value
end

Private Instance Methods

rails_filters() click to toggle source
# File lib/influx_reporter/filter.rb, line 58
def rails_filters
  if defined?(::Rails) && Rails.respond_to?(:application) && Rails.application
    if filters = ::Rails.application.config.filter_parameters
      filters.any? ? filters : nil
    end
  end
end
should_filter?(key) click to toggle source
# File lib/influx_reporter/filter.rb, line 47
def should_filter?(key)
  @params.any? do |param|
    case param
      when String, Symbol
        key.to_s == param.to_s
      when Regexp
        param.match(key)
    end
  end
end