lib/eco/api/session/config/workflow.rb in eco-helpers-3.0.19 vs lib/eco/api/session/config/workflow.rb in eco-helpers-3.0.20
- old
+ new
@@ -139,20 +139,22 @@
# @yieldparam exception [Exception] the exception object that was raised
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
# @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
def rescue(&block)
- return @rescue unless block
+ return @rescue unless block_given?
+
@rescue = block
self
end
# Prevent reserved word clash on DSL
alias_method :exception, :rescue
# Called on `SystemExit` exception
def exit_handle(&block)
- return @exit_handle unless block
+ return @exit_handle unless block_given?
+
@exit_handle = block
self
end
# Used in **configuration** time **add previous** `callbacks`
@@ -169,10 +171,11 @@
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
# @yieldreturn [Eco::API::UseCases::BaseIO] `io` the input/output object carried througout all the _workflow_
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
def before(key = nil, &block)
raise ArgumentError, "A block should be given." unless block_given?
+
if key
stage(key).before(&block)
else
@before.push(block)
end
@@ -193,10 +196,11 @@
# @yieldparam io [Eco::API::UseCases::BaseIO] the input/output object carried througout all the _workflow_
# @yieldreturn [Eco::API::UseCases::BaseIO] `io` the input/output object carried througout all the _workflow_
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
def after(key = nil, &block)
raise ArgumentError, "A block should be given." unless block_given?
+
if key
stage(key).after(&block)
else
@after.push(block)
end
@@ -265,19 +269,21 @@
@before.each do |c|
io = io_result(io: io) do
io.evaluate(self, io, &c)
end
end
+
io
end
def run_after(io)
@after.each do |c|
io = io_result(io: io) do
io.evaluate(self, io, &c)
end
end
+
io
end
def run_it(io, &block)
io.session.log(:debug) {
@@ -303,10 +309,11 @@
io = io_result(io: io) do
io.evaluate(self, io, &@on)
end
end
+
io
ensure
@pending = false
end
@@ -339,11 +346,15 @@
existing_stages.all?(&:ready?)
end
def stage(key)
self.class.validate_stage(key)
- @stages[key] ||= self.class.workflow_class(key).new(key, _parent: self, config: config)
+ @stages[key] ||= self.class.workflow_class(key).new(
+ key,
+ _parent: self,
+ config: config
+ )
end
# helper to treat trigger the exit and rescue handlers
def rescuable(io)
yield
@@ -352,17 +363,19 @@
# exit 1
rescue SystemExit => err
io = io_result(io: io) do
io.evaluate(err, io, &exit_handle)
end
+
exit err.status
rescue Interrupt => _int
raise
rescue StandardError => err
# raise unless self.rescue
io = io_result(io: io) do
io.evaluate(err, io, &self.rescue)
end
+
raise
end
end
end
end