Class: ContextExposer::Integrations::KeyFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/context_exposer/integrations/key_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of KeyFilter.



6
7
8
9
# File 'lib/context_exposer/integrations/key_filter.rb', line 6

def initialize keys, options = {}
  @keys = keys || []
  @options = options
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



4
5
6
# File 'lib/context_exposer/integrations/key_filter.rb', line 4

def keys
  @keys
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/context_exposer/integrations/key_filter.rb', line 4

def options
  @options
end

Instance Method Details

#exceptObject



17
18
19
# File 'lib/context_exposer/integrations/key_filter.rb', line 17

def except
  @except ||= symbolize_opts :except
end

#filterObject

expose all exposures exposed by decent_exposure to context



12
13
14
15
# File 'lib/context_exposer/integrations/key_filter.rb', line 12

def filter
  the_keys = keys - except
  only.empty? ? the_keys : the_keys.select {|k| only.include? k.to_sym } 
end

#onlyObject



21
22
23
# File 'lib/context_exposer/integrations/key_filter.rb', line 21

def only
  @only ||= symbolize_opts :only
end

#symbolize_opts(name) ⇒ Object



25
26
27
# File 'lib/context_exposer/integrations/key_filter.rb', line 25

def symbolize_opts name 
  (options[name.to_sym] || {}).map(&:to_sym)
end