Class: CrackPipe::Action
- Inherits:
-
Object
- Object
- CrackPipe::Action
- 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
-
.steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Attribute Summary collapse
-
#kwargs_overrides ⇒ Object
readonly
Returns the value of attribute kwargs_overrides.
Class Method Summary collapse
- .call(context = {}, &blk) ⇒ Object
-
.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?`.
Instance Method Summary collapse
-
#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.
-
#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.
- #call(context = {}) ⇒ Object
- #fail!(output = nil) ⇒ Object
- #failure?(output) ⇒ Boolean
-
#initialize(**kwargs_overrides, &blk) ⇒ Action
constructor
A new instance of Action.
- #pass!(output) ⇒ Object
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
.steps ⇒ Object (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_overrides ⇒ Object (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
80 81 82 |
# File 'lib/crack_pipe/action.rb', line 80 def failure?(output) output.is_a?(Result) ? output.failure? : !output end |