Class: Brainguy::ErrorHandlingNotifier
- Inherits:
-
BasicNotifier
- Object
- BasicNotifier
- Brainguy::ErrorHandlingNotifier
- Defined in:
- lib/brainguy/error_handling_notifier.rb
Overview
It is possible that errors may be raised when notifying listeners. This notifier wrapper class provides some leeway in how to handle those errors. It does this by capturing errors and applying a policy to them.
Includes a selection of common error policies.
Direct Known Subclasses
Constant Summary collapse
- SUPPRESS_STRATEGY =
The suppression strategy. Throws errors away.
->(_subscription, _error) do # NOOP end
- WARN_STRATEGY =
The warning strategy. Turns errors into warnings.
->(_subscription, error) do warn "#{error.class}: #{error.}" end
- RAISE_STRATEGY =
The raise strategy. Re-raises errors as if they had never been captured.
->(_subscription, error) do raise error end
Instance Method Summary collapse
-
#initialize(notifier, error_handler = RAISE_STRATEGY) ⇒ ErrorHandlingNotifier
constructor
A new instance of ErrorHandlingNotifier.
-
#notify(subscription) ⇒ @Object
Notify a
subscription
of an event, and apply the error policy to any exception that is raised. - #result ⇒ nil
Constructor Details
#initialize(notifier, error_handler = RAISE_STRATEGY) ⇒ ErrorHandlingNotifier
Returns a new instance of ErrorHandlingNotifier.
31 32 33 34 |
# File 'lib/brainguy/error_handling_notifier.rb', line 31 def initialize(notifier, error_handler = RAISE_STRATEGY) super(notifier) @error_handler = resolve_error_handler(error_handler) end |
Instance Method Details
#notify(subscription) ⇒ @Object
Notify a subscription
of an event, and apply the error policy to any
exception that is raised.
40 41 42 43 44 |
# File 'lib/brainguy/error_handling_notifier.rb', line 40 def notify(subscription, *) super rescue => error @error_handler.call(subscription, error) end |
#result ⇒ nil
47 48 49 |
# File 'lib/brainguy/error_handling_notifier.rb', line 47 def result nil end |