Class: DataRedactor::Railtie
- Inherits:
-
Rails::Railtie
- Object
- Rails::Railtie
- DataRedactor::Railtie
- Defined in:
- lib/data_redactor/railtie.rb
Overview
Rails wiring for data_redactor. Requiring this file installs a Railtie that
wraps the Rails logger's formatter and appends a filter_parameters entry,
so an app gets redaction without writing either integration by hand.
Rails is never a runtime dependency of the gem: this file is only loaded when the application requires it, following the same opt-in pattern as every other integration.
Class Method Summary collapse
-
.redaction_options(config) ⇒ Hash
private
only/exceptare read with[]rather than the OrderedOptions reader:onlyandexceptare Enumerable methods, so the reader would return a Method-backed result instead of nil when the app never set them. -
.wrap_logger(logger, options) ⇒ void
private
A BroadcastLogger writes to each of its sinks directly, so a formatter set on the broadcast itself never runs — each sink has to be wrapped instead.
Class Method Details
.redaction_options(config) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
only/except are read with [] rather than the OrderedOptions reader:
only and except are Enumerable methods, so the reader would return a
Method-backed result instead of nil when the app never set them.
41 42 43 44 45 46 47 |
# File 'lib/data_redactor/railtie.rb', line 41 def self.(config) { only: config[:only], except: config[:except], placeholder: config.placeholder } end |
.wrap_logger(logger, options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
A BroadcastLogger writes to each of its sinks directly, so a formatter set on the broadcast itself never runs — each sink has to be wrapped instead.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/data_redactor/railtie.rb', line 75 def self.wrap_logger(logger, ) return if logger.nil? if logger.respond_to?(:broadcasts) logger.broadcasts.each { |sink| wrap_logger(sink, ) } return end return unless logger.respond_to?(:formatter) && logger.respond_to?(:formatter=) inner = logger.formatter || ::Logger::Formatter.new return if inner.is_a?(Integrations::Logger) logger.formatter = Integrations::Logger.new(inner: inner, **) end |