Module: Auth::Sanitizer::FilteredAttributes
- Defined in:
- lib/auth/sanitizer/filtered_attributes.rb
Overview
Mixin that redacts sensitive instance variables in ‘#inspect` output.
Classes include this module and declare which attribute names should be filtered via filtered_attributes. Matching and replacement behavior is delegated to ThingFilter, which is initialized once per object.
This means existing objects keep the filter configuration that was present when they were initialized, even if global config or class-level filter declarations change later.
The label used for redaction is resolved from filtered_label at object initialization time. Host gems may customize this by installing a provider via filtered_label_provider=.
Defined Under Namespace
Modules: ClassMethods, InitializerMethods
Class Method Summary collapse
-
.included(base) ⇒ void
Hook invoked when the module is included.
Instance Method Summary collapse
-
#inspect ⇒ String
Custom inspect that redacts configured attributes.
-
#thing_filter ⇒ ThingFilter
The initialized thing filter used by this object.
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
Hook invoked when the module is included. Extends the including class with class-level helpers and prepends the initializer hook.
25 26 27 28 |
# File 'lib/auth/sanitizer/filtered_attributes.rb', line 25 def included(base) base.extend(ClassMethods) base.prepend(InitializerMethods) end |
Instance Method Details
#inspect ⇒ String
Custom inspect that redacts configured attributes.
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/auth/sanitizer/filtered_attributes.rb', line 95 def inspect return super if thing_filter.things.empty? inspected_vars = instance_variables.map do |var| if thing_filter.filtered?(var) "#{var}=#{thing_filter.label}" else "#{var}=#{instance_variable_get(var).inspect}" end end "#<#{self.class}:#{object_id} #{inspected_vars.join(", ")}>" end |
#thing_filter ⇒ ThingFilter
The initialized thing filter used by this object.
This is a per-instance snapshot created during initialization.
88 89 90 |
# File 'lib/auth/sanitizer/filtered_attributes.rb', line 88 def thing_filter @thing_filter end |