Class: Julewire::Redaction::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/redaction/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filters) ⇒ Matcher

Returns a new instance of Matcher.



8
9
10
11
12
13
14
15
# File 'lib/julewire/redaction/matcher.rb', line 8

def initialize(filters)
  @blocks, patterns = Array(filters).partition { it.is_a?(Proc) }
  normal_filters, deep_filters = patterns.partition { !deep_filter?(it) }
  @pattern = compile(normal_filters, deep: false)
  @deep_pattern = compile(deep_filters, deep: true)
  @string_scan_pattern = string_scan_pattern(normal_filters)
  @blocks.freeze
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



6
7
8
# File 'lib/julewire/redaction/matcher.rb', line 6

def blocks
  @blocks
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


22
# File 'lib/julewire/redaction/matcher.rb', line 22

def empty? = @pattern.nil? && @deep_pattern.nil?

#match?(key, path: nil) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/julewire/redaction/matcher.rb', line 17

def match?(key, path: nil)
  key_string = key.to_s
  !!(pattern_match?(@pattern, key_string) || pattern_match?(@deep_pattern, path))
end

#path_dependent?Boolean

Returns:

  • (Boolean)


24
# File 'lib/julewire/redaction/matcher.rb', line 24

def path_dependent? = !@deep_pattern.nil?

#string_key_possible?(value) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/julewire/redaction/matcher.rb', line 26

def string_key_possible?(value)
  return true unless @string_scan_pattern

  @string_scan_pattern.match?(value)
end