Class: Brainguy::ErrorCollectingNotifier

Inherits:
ErrorHandlingNotifier show all
Defined in:
lib/brainguy/error_collecting_notifier.rb

Overview

A notifier wrapper that captures exceptions and collects them into a Hash.

Constant Summary

Constants inherited from ErrorHandlingNotifier

Brainguy::ErrorHandlingNotifier::RAISE_STRATEGY, Brainguy::ErrorHandlingNotifier::SUPPRESS_STRATEGY, Brainguy::ErrorHandlingNotifier::WARN_STRATEGY

Instance Method Summary collapse

Methods inherited from ErrorHandlingNotifier

#notify

Methods inherited from BasicNotifier

#notify

Constructor Details

#initialize(notifier) ⇒ ErrorCollectingNotifier

Returns a new instance of ErrorCollectingNotifier.

Parameters:

  • notifier (#notify)

    the notifier to wrap

  • error_handler (:call)

    a callable that determined error policy There are some symbolic shortcuts available here:

    • :suppress: Suppress errors completely.
    • :warn: Convert errors to warnings.
    • :raise: Re-raise errors.

7
8
9
10
# File 'lib/brainguy/error_collecting_notifier.rb', line 7

def initialize(notifier)
  super(notifier, method(:add_error))
  @errors = {}
end

Instance Method Details

#add_error(subscription, error) ⇒ Object

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.

Add another error to the list


14
15
16
# File 'lib/brainguy/error_collecting_notifier.rb', line 14

def add_error(subscription, error)
  @errors[subscription] = error
end

#resultHash{Subscription => Exception}

Return list of errors captured while notifying subscriptions. One entry for every subscription that raised an error.

Returns:


22
23
24
# File 'lib/brainguy/error_collecting_notifier.rb', line 22

def result
  @errors
end