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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 30 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
54 55 56 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 54 def callback_active? Fiber[ACTIVE_KEY] == true end |
.failure(class_name, metadata) ⇒ Object
58 59 60 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 58 def failure(class_name, ) Failure.new(at: Time.now.utc, class_name: class_name, metadata: || {}) end |
.failure?(result) ⇒ Boolean
46 47 48 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 46 def failure?(result) result.instance_of?(Failure) end |
.nested_callback_result(metadata) ⇒ Object
50 51 52 |
# File 'lib/julewire/core/diagnostics/callback_notifier.rb', line 50 def nested_callback_result() failure(NestedCallback.name, ) end |