class Opbeat::Filter
@api private
Constants
- MASK
Attributes
config[R]
Public Class Methods
new(config)
click to toggle source
# File lib/opbeat/filter.rb, line 7 def initialize config @config = config @params = rails_filters || config.filter_parameters end
Public Instance Methods
apply(data, opts = {})
click to toggle source
# File lib/opbeat/filter.rb, line 14 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/opbeat/filter.rb, line 33 def apply_to_hash hsh hsh.inject({}) do |filtered, kv| key, value = kv filtered[key] = sanitize(key, value) filtered end end
apply_to_string(str, opts = {})
click to toggle source
# File lib/opbeat/filter.rb, line 23 def apply_to_string str, opts = {} sep = opts[:separator] || '&'.freeze kv_sep = opts[:kv_separator] || '='.freeze 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/opbeat/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/opbeat/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/opbeat/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