Module: SmartCore::Engine::RescueExt
- Defined in:
- lib/smart_core/engine/rescue_ext.rb
Overview
Class Method Summary collapse
-
.inline_rescue_pipe(*proks, &error_interceptor) ⇒ Any
rubocop:disable Performance/RedundantBlockCall.
Class Method Details
.inline_rescue_pipe(*proks, &error_interceptor) ⇒ Any
rubocop:disable Performance/RedundantBlockCall
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/smart_core/engine/rescue_ext.rb', line 19 def inline_rescue_pipe(*proks, &error_interceptor) unless proks.all? { |prok| prok.is_a?(::Proc) } raise(SmartCore::ArgumentError, 'Invalid proc object') end interceptable_bloks = proks.to_enum pipe_invokation_result = nil last_exception = nil begin while current_block = interceptable_bloks.next begin pipe_invokation_result = current_block.call break rescue => error last_exception = error end end pipe_invokation_result rescue ::StopIteration error_interceptor ? error_interceptor.call(last_exception) : raise(last_exception) end end |