Module: Julewire::Core::Diagnostics::CallbackNotifier
- Defined in:
- lib/julewire/core/diagnostics/callback_notifier.rb
Defined Under Namespace
Classes: Failure
Class Method Summary collapse
- .call(callback, first_argument, metadata) ⇒ Object
- .callback_active? ⇒ Boolean
- .failure(class_name, metadata) ⇒ Object
- .failure?(result) ⇒ Boolean
- .nested_callback_result(metadata) ⇒ Object
Class Method Details
.call(callback, first_argument, metadata) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 28 def call(callback, first_argument, ) return unless callback return nested_callback_result() if callback_active? previous = Fiber[ACTIVE_KEY] begin Fiber[ACTIVE_KEY] = true callback.call(first_argument, ) true rescue StandardError => e failure(e.class.name, ) ensure Fiber[ACTIVE_KEY] = previous end end |
.callback_active? ⇒ Boolean
52 53 54 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 52 def callback_active? Fiber[ACTIVE_KEY] == true end |
.failure(class_name, metadata) ⇒ Object
56 57 58 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 56 def failure(class_name, ) Failure.new(at: Time.now.utc, class_name: class_name, metadata: || {}) end |
.failure?(result) ⇒ Boolean
44 45 46 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 44 def failure?(result) result.is_a?(Failure) end |
.nested_callback_result(metadata) ⇒ Object
48 49 50 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 48 def nested_callback_result() failure(NestedCallback.name, ) end |