Class: CrackPipe::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/crack_pipe/action.rb,
lib/crack_pipe/action/exec.rb,
lib/crack_pipe/action/step.rb,
lib/crack_pipe/action/result.rb,
lib/crack_pipe/action/signal.rb

Overview

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.

Defined Under Namespace

Modules: Exec Classes: Result, Signal, Step

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs_overrides, &blk) ⇒ Action

Returns a new instance of Action.



49
50
51
52
# File 'lib/crack_pipe/action.rb', line 49

def initialize(**kwargs_overrides, &blk)
  @__wrapper__ = block_given? ? blk : nil
  @kwargs_overrides = kwargs_overrides
end

Class Attribute Details

.stepsObject (readonly)

Returns the value of attribute steps.



17
18
19
# File 'lib/crack_pipe/action.rb', line 17

def steps
  @steps
end

Instance Attribute Details

#kwargs_overridesObject (readonly)

Returns the value of attribute kwargs_overrides.



47
48
49
# File 'lib/crack_pipe/action.rb', line 47

def kwargs_overrides
  @kwargs_overrides
end

Class Method Details

.call(context = {}, &blk) ⇒ Object



19
20
21
# File 'lib/crack_pipe/action.rb', line 19

def call(context = {}, *, &blk)
  new(&blk).call(context)
end

.inherited(subclass) ⇒ Object

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



27
28
29
30
# File 'lib/crack_pipe/action.rb', line 27

def inherited(subclass)
  subclass.instance_variable_set(:@steps, @steps.dup)
  super
end

Instance Method Details

#after_flow_control(flow_control_hash) ⇒ Object

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.



63
64
65
# File 'lib/crack_pipe/action.rb', line 63

def after_flow_control(flow_control_hash)
  flow_control_hash
end

#after_step(output) ⇒ Object

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



72
73
74
# File 'lib/crack_pipe/action.rb', line 72

def after_step(output)
  output
end

#call(context = {}) ⇒ Object



54
55
56
57
# 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) ⇒ Object



76
77
78
# File 'lib/crack_pipe/action.rb', line 76

def fail!(output = nil)
  Exec.halt(output, false)
end

#failure?(output) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/crack_pipe/action.rb', line 80

def failure?(output)
  output.is_a?(Result) ? output.failure? : !output
end

#pass!(output) ⇒ Object



84
85
86
# File 'lib/crack_pipe/action.rb', line 84

def pass!(output)
  Exec.halt(output, true)
end