Module: OAuth2::FilteredAttributes
- Included in:
- AccessToken, Authenticator, Client
- Defined in:
- lib/oauth2/filtered_attributes.rb
Overview
Mixin that redacts sensitive instance variables in #inspect output.
Classes include this module and declare which attributes should be filtered using filtered_attributes. Any instance variable name that includes one of those attribute names will be shown as [FILTERED] in the object’s inspect.
Defined Under Namespace
Modules: ClassMethods
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.
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.
13 14 15 |
# File 'lib/oauth2/filtered_attributes.rb', line 13 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#inspect ⇒ String
Custom inspect that redacts configured attributes.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/oauth2/filtered_attributes.rb', line 38 def inspect filtered_attribute_names = self.class.filtered_attribute_names return super if filtered_attribute_names.empty? inspected_vars = instance_variables.map do |var| if filtered_attribute_names.any? { |filtered_var| var.to_s.include?(filtered_var.to_s) } "#{var}=[FILTERED]" else "#{var}=#{instance_variable_get(var).inspect}" end end "#<#{self.class}:#{object_id} #{inspected_vars.join(", ")}>" end |