Class: Julewire::Redaction::Matcher
- Inherits:
-
Object
- Object
- Julewire::Redaction::Matcher
- Defined in:
- lib/julewire/redaction/matcher.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(filters) ⇒ Matcher
constructor
A new instance of Matcher.
- #match?(key, path: nil) ⇒ Boolean
- #path_dependent? ⇒ Boolean
- #string_key_possible?(value) ⇒ Boolean
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
#blocks ⇒ Object (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
22 |
# File 'lib/julewire/redaction/matcher.rb', line 22 def empty? = @pattern.nil? && @deep_pattern.nil? |
#match?(key, path: nil) ⇒ 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
24 |
# File 'lib/julewire/redaction/matcher.rb', line 24 def path_dependent? = !@deep_pattern.nil? |
#string_key_possible?(value) ⇒ 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 |