Class: Auth::Sanitizer::ThingFilter
- Inherits:
-
Object
- Object
- Auth::Sanitizer::ThingFilter
- Defined in:
- lib/auth/sanitizer/thing_filter.rb
Overview
Small value object for matching and filtering named things.
Used by multiple filtering surfaces in the library, such as inspected object attributes and debug-log key filtering.
‘ThingFilter` snapshots and duplicates its inputs on initialization so later mutation of caller-owned arrays or strings does not affect existing filter instances.
Instance Attribute Summary collapse
-
#label ⇒ String
readonly
The configured replacement label.
-
#pattern_source ⇒ String
readonly
Build a regular-expression source for the configured thing names.
-
#things ⇒ Array<String>
readonly
The configured names that should be filtered.
Instance Method Summary collapse
-
#filtered?(thing_name) ⇒ Boolean
True when the provided name matches any configured filter entry.
-
#initialize(things, label:) ⇒ ThingFilter
constructor
Create a new filter.
Constructor Details
#initialize(things, label:) ⇒ ThingFilter
Create a new filter.
The provided values are duplicated and frozen so the filter remains stable for the lifetime of the object.
21 22 23 24 25 |
# File 'lib/auth/sanitizer/thing_filter.rb', line 21 def initialize(things, label:) @things = Array(things).map { |thing| thing.to_s.dup.freeze }.freeze @label = label.to_s.dup.freeze @pattern_source = Regexp.union(@things).source.freeze end |
Instance Attribute Details
#label ⇒ String (readonly)
The configured replacement label.
35 36 37 |
# File 'lib/auth/sanitizer/thing_filter.rb', line 35 def label @label end |
#pattern_source ⇒ String (readonly)
Build a regular-expression source for the configured thing names.
Useful when a filtering surface needs regex-based replacement rather than direct name checks.
55 56 57 |
# File 'lib/auth/sanitizer/thing_filter.rb', line 55 def pattern_source @pattern_source end |
#things ⇒ Array<String> (readonly)
The configured names that should be filtered.
30 31 32 |
# File 'lib/auth/sanitizer/thing_filter.rb', line 30 def things @things end |
Instance Method Details
#filtered?(thing_name) ⇒ Boolean
True when the provided name matches any configured filter entry.
Matching is substring-based so it works naturally with instance-variable names used by ‘#inspect`, such as `@secret` matching `secret`.
44 45 46 47 |
# File 'lib/auth/sanitizer/thing_filter.rb', line 44 def filtered?(thing_name) thing_name_str = thing_name.to_s things.any? { |thing| thing_name_str.include?(thing) } end |