lib/eco/api/session/config/workflow.rb in eco-helpers-3.0.4 vs lib/eco/api/session/config/workflow.rb in eco-helpers-3.0.5
- old
+ new
@@ -54,10 +54,11 @@
@after = []
end
def name(with_path: false)
return @name if !with_path || root?
+
[@_parent.name(with_path: true), @name].compact.join('.')
end
# Has this stage run yet?
# @note it does **not** include _sub-stages_ that run `before`
@@ -78,10 +79,11 @@
# - `false` if the current _stage_ is `root?` (the top stage of the hierarchy)
# - `true` if its parent task is to be skipped
def skip?
return @skip if instance_variable_defined?(:@skip)
return false if root?
+
@_parent.skip?
end
# Used in **configuration** time **to configure** the _workflow_ of the target (sub)stage `key`
# @note
@@ -95,13 +97,15 @@
# @return [Eco::API::Session::Config::Workflow]
# 1. if block is provided provided, it returns the **current stage** object (to ease chainig).
# 2. if block is not provided, it returns the **stage** referred by `key`
def for(key = nil, &block)
raise ArgumentError, "With no 'key', a block should be given." unless key || block_given?
+
tap do
next yield(self) unless key
next stage(key).for(&block) if block_given?
+
return stage(key)
end
end
alias_method :with, :for
@@ -116,15 +120,17 @@
# @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 on(key = nil, &block)
raise ArgumentError, "A block should be given." unless block_given?
+
if key
stage(key).on(&block)
else
@on = block
end
+
self
end
# When there is an `Exception`, you might have defined some `callback`
# to do something with it (i.e. register, email)
@@ -245,10 +251,11 @@
@_parent == self
end
def path
return name if root?
+
"#{@_parent.path}:#{name}"
end
def ready?
!!@on
@@ -271,11 +278,14 @@
end
io
end
def run_it(io, &block)
- io.session.logger.debug("(Workflow: #{path}) running now")
+ io.session.log(:debug) {
+ "(Workflow: #{path}) running now"
+ }
+
if block
io = io_result(io: io) do
io.evaluate(self, io, &block)
end
else
@@ -284,12 +294,14 @@
stg.run(io: io)
end
end
unless ready?
- msg = "(Workflow: #{path}) 'on' callback is not defined, nor block given"
- io.session.logger.debug(msg)
+ io.session.log(:debug) {
+ "(Workflow: #{path}) 'on' callback is not defined, nor block given"
+ }
end
+
io = io_result(io: io) do
io.evaluate(self, io, &@on)
end
end
io