class CrackPipe::Action
NOTE: The reason for using an instantiated class rather than doing all of this functionally, since there is no real state data, is so that symbols operate as instance methods and that procs and the like are executed with `instance_exec`, giving them access to the local scope.
Attributes
Public Class Methods
# File lib/crack_pipe/action.rb, line 19 def call(context = {}, *, &blk) new(&blk).call(context) end
NOTE: In general, the only time you should use inheritence is when created a more specilized generic action with some of its own methods similar such as `pass!` or overiding behavior in `after_step` or `failure?`.
# File lib/crack_pipe/action.rb, line 27 def inherited(subclass) subclass.instance_variable_set(:@steps, @steps.dup) super end
# File lib/crack_pipe/action.rb, line 49 def initialize(**kwargs_overrides, &blk) @__wrapper__ = block_given? ? blk : nil @kwargs_overrides = kwargs_overrides end
Private Class Methods
# File lib/crack_pipe/action.rb, line 34 def fail(exec = nil, **kwargs, &blk) step(exec, kwargs.merge(track: :fail), &blk) end
# File lib/crack_pipe/action.rb, line 38 def pass(exec = nil, **kwargs, &blk) step(exec, kwargs.merge(always_pass: true), &blk) end
# File lib/crack_pipe/action.rb, line 42 def step(*args, &blk) @steps += [Step.new(*args, &blk)] end
Public Instance Methods
NOTE: This hook is here if you absolutely must do something to mutate the last flow control hash after a step has been executed. You can alter the context before it is passed to another step, insert a signal, or even pass custom key/value pairs that may be useful for debugging.
# File lib/crack_pipe/action.rb, line 63 def after_flow_control(flow_control_hash) flow_control_hash end
NOTE: While this hook does nothing by default, it is here with the intention of dealing with potential default values being generated either for output or adding values to the context. A common example would be returning some kind of default failure object in place of a literal `nil` or `false`.
# File lib/crack_pipe/action.rb, line 72 def after_step(output) output end
# File lib/crack_pipe/action.rb, line 54 def call(context = {}, *) return @__wrapper__.call(Exec.(self, context)) if @__wrapper__ Exec.(self, context) end
# File lib/crack_pipe/action.rb, line 76 def fail!(output = nil) Exec.halt(output, false) end
# File lib/crack_pipe/action.rb, line 80 def failure?(output) output.is_a?(Result) ? output.failure? : !output end
# File lib/crack_pipe/action.rb, line 84 def pass!(output) Exec.halt(output, true) end