Class: Core::Pipeline::Callable
- Inherits:
-
Object
- Object
- Core::Pipeline::Callable
- Includes:
- Inspect
- Defined in:
- lib/core/pipeline/callable.rb
Overview
[public] Calls a pipeline on a pipelined object.
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#compiler ⇒ Object
writeonly
[public].
-
#skipped ⇒ Object
readonly
Returns the value of attribute skipped.
Instance Method Summary collapse
-
#action(*args, before: nil, after: nil, context: nil, curry: false, &block) ⇒ Object
[public] Defines a pipeline action.
-
#any? ⇒ Boolean
[public] Returns true if the pipeline will call any actions.
-
#call(object) ⇒ Object
[public] Calls the pipeline in context of an object with the given arguments.
-
#exclude(pipeline) ⇒ Object
[public] Excludes actions from the given pipeline.
-
#finalize ⇒ Object
[public] Finalizes the pipeline.
-
#include(pipeline) ⇒ Object
[public] Includes actions from the given pipeline.
-
#initialize(object) ⇒ Callable
constructor
A new instance of Callable.
- #initialize_copy ⇒ Object
-
#relocate(object) ⇒ Object
[public] Relocates to another object context.
-
#skip(name) ⇒ Object
[public] Skips the given action.
-
#use(pipeline) ⇒ Object
[public] Replaces existing actions with actions from the given pipeline.
Constructor Details
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
31 32 33 |
# File 'lib/core/pipeline/callable.rb', line 31 def actions @actions end |
#compiler=(value) ⇒ Object (writeonly)
[public]
36 37 38 |
# File 'lib/core/pipeline/callable.rb', line 36 def compiler=(value) @compiler = value end |
#skipped ⇒ Object (readonly)
Returns the value of attribute skipped.
32 33 34 |
# File 'lib/core/pipeline/callable.rb', line 32 def skipped @skipped end |
Instance Method Details
#action(*args, before: nil, after: nil, context: nil, curry: false, &block) ⇒ Object
[public] Defines a pipeline action.
52 53 54 55 |
# File 'lib/core/pipeline/callable.rb', line 52 def action(*args, before: nil, after: nil, context: nil, curry: false, &block) @actions << Action.build(*args, before: before, after: after, context: context, curry: curry, &block) recompile if compiled? end |
#any? ⇒ Boolean
[public] Returns true if the pipeline will call any actions.
46 47 48 |
# File 'lib/core/pipeline/callable.rb', line 46 def any? (@actions.map(&:name) - @skipped).any? end |
#call(object) ⇒ Object
[public] Calls the pipeline in context of an object with the given arguments.
104 105 106 |
# File 'lib/core/pipeline/callable.rb', line 104 def call(object, ...) finalize.call(object, ...) end |
#exclude(pipeline) ⇒ Object
[public] Excludes actions from the given pipeline.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/core/pipeline/callable.rb', line 91 def exclude(pipeline) if (pipeline.is_a?(Class) || pipeline.is_a?(Module)) && pipeline.ancestors.include?(Core::Pipeline) pipeline.pipeline.actions.each do |action| @actions.delete(action) recompile if compiled? end else raise ArgumentError, "expected a pipeline" end end |
#finalize ⇒ Object
[public] Finalizes the pipeline.
110 111 112 113 114 |
# File 'lib/core/pipeline/callable.rb', line 110 def finalize compile self end |
#include(pipeline) ⇒ Object
[public] Includes actions from the given pipeline.
80 81 82 83 84 85 86 87 |
# File 'lib/core/pipeline/callable.rb', line 80 def include(pipeline) if (pipeline.is_a?(Class) || pipeline.is_a?(Module)) && pipeline.ancestors.include?(Core::Pipeline) @actions.concat(pipeline.pipeline.actions) recompile if compiled? else raise ArgumentError, "expected a pipeline" end end |
#initialize_copy ⇒ Object
25 26 27 28 29 |
# File 'lib/core/pipeline/callable.rb', line 25 def initialize_copy(...) @actions = @actions.clone @skipped = @skipped.clone super end |
#relocate(object) ⇒ Object
[public] Relocates to another object context.
40 41 42 |
# File 'lib/core/pipeline/callable.rb', line 40 def relocate(object) @object = object end |
#skip(name) ⇒ Object
[public] Skips the given action.
59 60 61 62 |
# File 'lib/core/pipeline/callable.rb', line 59 def skip(name) @skipped << name.to_sym recompile if compiled? end |
#use(pipeline) ⇒ Object
[public] Replaces existing actions with actions from the given pipeline.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/core/pipeline/callable.rb', line 66 def use(pipeline) if (pipeline.is_a?(Class) || pipeline.is_a?(Module)) && pipeline.ancestors.include?(Core::Pipeline) @mutex.synchronize do @actions.clear @actions.concat(pipeline.pipeline.actions) recompile if compiled? end else raise ArgumentError, "expected a pipeline" end end |