Class: SoftValidator::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- SoftValidator::LogSubscriber
- Defined in:
- lib/soft_validator/log_subscriber.rb
Overview
Log subscriber for soft validation errors.
Class Method Summary collapse
-
.attach ⇒ Object
Helper method to attach the log subscriber.
-
.detach ⇒ Object
Helper method to detach the log subscriber.
Instance Method Summary collapse
Class Method Details
.attach ⇒ Object
Helper method to attach the log subscriber.
7 8 9 |
# File 'lib/soft_validator/log_subscriber.rb', line 7 def attach attach_to :soft_validator end |
.detach ⇒ Object
Helper method to detach the log subscriber.
12 13 14 |
# File 'lib/soft_validator/log_subscriber.rb', line 12 def detach detach_from :soft_validator end |
Instance Method Details
#logger ⇒ Object
29 30 31 |
# File 'lib/soft_validator/log_subscriber.rb', line 29 def logger self.class.logger end |
#validation_error(event) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/soft_validator/log_subscriber.rb', line 17 def validation_error(event) return unless logger&.warn? error = event.payload[:error] record = error.base ref = record.class.name ref = "#{ref}(#{record.id})" if record.respond_to?(:id) = "Soft validation error on #{ref}: #{error.full_message}" logger.warn() end |