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

steps[R]
kwargs_overrides[R]

Public Class Methods

call(context = {}, *, &blk) click to toggle source
# File lib/crack_pipe/action.rb, line 19
def call(context = {}, *, &blk)
  new(&blk).call(context)
end
inherited(subclass) click to toggle source

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?`.

Calls superclass method
# File lib/crack_pipe/action.rb, line 27
def inherited(subclass)
  subclass.instance_variable_set(:@steps, @steps.dup)
  super
end
new(**kwargs_overrides, &blk) click to toggle source
# 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

fail(exec = nil, **kwargs, &blk) click to toggle source
# File lib/crack_pipe/action.rb, line 34
def fail(exec = nil, **kwargs, &blk)
  step(exec, kwargs.merge(track: :fail), &blk)
end
pass(exec = nil, **kwargs, &blk) click to toggle source
# File lib/crack_pipe/action.rb, line 38
def pass(exec = nil, **kwargs, &blk)
  step(exec, kwargs.merge(always_pass: true), &blk)
end
step(*args, &blk) click to toggle source
# File lib/crack_pipe/action.rb, line 42
def step(*args, &blk)
  @steps += [Step.new(*args, &blk)]
end

Public Instance Methods

after_flow_control(flow_control_hash) click to toggle source

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
after_step(output) click to toggle source

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
call(context = {}, *) click to toggle source
# File lib/crack_pipe/action.rb, line 54
def call(context = {}, *)
  return @__wrapper__.call(Exec.(self, context)) if @__wrapper__
  Exec.(self, context)
end
fail!(output = nil) click to toggle source
# File lib/crack_pipe/action.rb, line 76
def fail!(output = nil)
  Exec.halt(output, false)
end
failure?(output) click to toggle source
# File lib/crack_pipe/action.rb, line 80
def failure?(output)
  output.is_a?(Result) ? output.failure? : !output
end
pass!(output) click to toggle source
# File lib/crack_pipe/action.rb, line 84
def pass!(output)
  Exec.halt(output, true)
end