Class: RightSupport::Notifier::Blacklister::Canonical
- 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
Class Method Summary collapse
- .normalize_keys(keys) ⇒ Object
-
.to_canonical(key) ⇒ Object
canonicalizes a key (header name) for easy lookup in a Rack env hash.
Instance Method Summary collapse
-
#filter(data) ⇒ Object
implements RightSupport::Notifier::Blacklister::Base#filter.
-
#initialize(keys, options = {}) ⇒ Canonical
constructor
A new instance of Canonical.
Constructor Details
#initialize(keys, options = {}) ⇒ Canonical
Returns a new instance of Canonical.
34 35 36 37 |
# File 'lib/right_support/notifiers/blacklisters/canonical.rb', line 34 def initialize(keys, = {}) super() @keys = ::RightSupport::Notifier::Blacklister::Canonical.normalize_keys(keys) end |
Class Method Details
.normalize_keys(keys) ⇒ Object
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.
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 |