Class: RightSupport::Notifier::Blacklister::Canonical

Inherits:
Base
  • Object
show all
Defined in:
lib/right_support/notifiers/blacklisters/canonical.rb

Overview

implements a blacklister that matches canonical keys. a canonical key follows the request/response header naming pattern(s) and/or can be converted to one of these naming patterns.

Instance Attribute Summary

Attributes inherited from Base

#replacement_value

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keys, options = {}) ⇒ Canonical

Returns a new instance of Canonical.

Parameters:

  • keys (Array|String)

    to blacklist

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :replacement_value (Object)

    of any kind including nil. default=‘HIDDEN’.



34
35
36
37
# File 'lib/right_support/notifiers/blacklisters/canonical.rb', line 34

def initialize(keys, options = {})
  super(options)
  @keys = ::RightSupport::Notifier::Blacklister::Canonical.normalize_keys(keys)
end

Class Method Details

.normalize_keys(keys) ⇒ Object

Parameters:

  • keys (Array|String)

    to normalize



50
51
52
# File 'lib/right_support/notifiers/blacklisters/canonical.rb', line 50

def self.normalize_keys(keys)
  ::Set.new(Array(keys).map(&self.method(:to_canonical)))
end

.to_canonical(key) ⇒ Object

canonicalizes a key (header name) for easy lookup in a Rack env hash.

Parameters:

  • key (String|Symbol)

    to canonicalize



57
58
59
# File 'lib/right_support/notifiers/blacklisters/canonical.rb', line 57

def self.to_canonical(key)
  key.to_s.upcase.gsub('-', '_')
end

Instance Method Details

#filter(data) ⇒ Object

implements RightSupport::Notifier::Blacklister::Base#filter



40
41
42
43
44
45
46
47
# File 'lib/right_support/notifiers/blacklisters/canonical.rb', line 40

def filter(data)
  data.keys.each do |key|
    if @keys.include?(self.class.to_canonical(key))
      data[key] = replacement_value
    end
  end
  true
end