Class: Logasm::Preprocessors::Blacklist

Inherits:
Object
  • Object
show all
Defined in:
lib/logasm/preprocessors/blacklist.rb

Defined Under Namespace

Classes: UnsupportedActionException

Constant Summary collapse

DEFAULT_ACTION =
'prune'
MASK_SYMBOL =
'*'
MASKED_VALUE =
MASK_SYMBOL * 5

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Blacklist

Returns a new instance of Blacklist.



12
13
14
15
16
17
18
19
# File 'lib/logasm/preprocessors/blacklist.rb', line 12

def initialize(config = {})
  @fields_to_process = config[:fields].inject({}) do |mem, field|
    key = field.delete(:key)
    options = {action: DEFAULT_ACTION}.merge(field)
    validate_action_supported(options[:action])
    mem.merge(key => options)
  end
end

Instance Method Details

#process(data) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/logasm/preprocessors/blacklist.rb', line 21

def process(data)
  if data.is_a? Hash
    data.inject({}) do |mem, (key, val)|
      if (field = @fields_to_process[key.to_s])
        self.send(action_method(field[:action]), mem, key, val)
      else
        mem.merge(key => process(val))
      end
    end
  elsif data.is_a? Array
    data.inject([]) do |mem, val|
      mem + [process(val)]
    end
  else
    data
  end
end