Class: TeeLogger::Filter::Recursive

Inherits:
FilterBase show all
Defined in:
lib/teelogger/filters/recursive.rb

Overview

The Recursive filter takes Hashes or Arrays, and recursively applies the other filters to their values.

Constant Summary collapse

FILTER_TYPES =
[Enumerable]
WINDOW_SIZE =
1

Instance Attribute Summary

Attributes inherited from FilterBase

#run_data

Instance Method Summary collapse

Methods inherited from FilterBase

#initialize

Constructor Details

This class inherits a constructor from TeeLogger::Filter::FilterBase

Instance Method Details

#process(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/teelogger/filters/recursive.rb', line 19

def process(*args)
  # For each argument, recurse processing. Note that due to the window
  # size of one, args is only an element long - but let's write this out
  # properly.
  processed_args = []

  args.each do |arg|
    # So we have an Enumerable, but we don't know whether it's Array-like
    # or Hash-like. We'll check whether it responds to ".keys", and then
    # treat it as a Hash.
    processed = nil
    if arg.respond_to? :keys
      processed = {}
      # Looks like a Hash, treat it like a Hash
      arg.each do |key, value|

        # If the key is a match, we'll just redact the entire value.
        redacted = false
        run_data[:words].each do |word|
          if word.match(key.to_s)
             processed[key] = ::TeeLogger::Filter::REDACTED_WORD
             redacted = true
             break
          end
        end

        # Otherwise, pass it through
        if not redacted
          processed[key] = run_data[:filters].apply_filters_internal(run_data, value)[0]
        end
      end
    else
      # Treat it like an Array
      processed = run_data[:filters].apply_filters_internal(run_data, *arg)
    end

    processed_args << processed
  end

  return processed_args
end