Class: Core::Pipeline::Callable
- Inherits:
-
Object
- Object
- Core::Pipeline::Callable
- 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.
-
#skipped ⇒ Object
readonly
Returns the value of attribute skipped.
Instance Method Summary collapse
-
#action(*args, before: nil, after: nil, context: nil, &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.
-
#include(pipeline) ⇒ Object
- public
-
Includes actions from the given pipeline.
-
#initialize(object) ⇒ Callable
constructor
A new instance of Callable.
-
#skip(name) ⇒ Object
- public
-
Skips the given action.
-
#use(pipeline) ⇒ Object
- public
-
Replaces existing actions with actions from the given pipeline.
Constructor Details
#initialize(object) ⇒ Callable
Returns a new instance of Callable.
16 17 18 19 20 21 |
# File 'lib/core/pipeline/callable.rb', line 16 def initialize(object) @object = object @mutex = Mutex.new @actions = [] @skipped = [] end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
23 24 25 |
# File 'lib/core/pipeline/callable.rb', line 23 def actions @actions end |
#skipped ⇒ Object (readonly)
Returns the value of attribute skipped.
24 25 26 |
# File 'lib/core/pipeline/callable.rb', line 24 def skipped @skipped end |
Instance Method Details
#action(*args, before: nil, after: nil, context: nil, &block) ⇒ Object
- public
-
Defines a pipeline action.
34 35 36 |
# File 'lib/core/pipeline/callable.rb', line 34 def action(*args, before: nil, after: nil, context: nil, &block) @actions << Action.build(*args, before: before, after: after, context: context, &block) end |
#any? ⇒ Boolean
- public
-
Returns true if the pipeline will call any actions.
28 29 30 |
# File 'lib/core/pipeline/callable.rb', line 28 def any? (@actions.map(&:name) - @skipped).any? end |
#call(object) ⇒ Object
- public
-
Calls the pipeline in context of an object with the given arguments.
81 82 83 |
# File 'lib/core/pipeline/callable.rb', line 81 def call(object, ...) compile.call(object, ...) end |
#exclude(pipeline) ⇒ Object
- public
-
Excludes actions from the given pipeline.
69 70 71 72 73 74 75 76 77 |
# File 'lib/core/pipeline/callable.rb', line 69 def exclude(pipeline) if (pipeline.is_a?(Class) || pipeline.is_a?(Module)) && pipeline.ancestors.include?(Is::Pipeline) pipeline.pipeline.actions.each do |action| @actions.delete(action) end else raise ArgumentError, "expected a pipeline" end end |
#include(pipeline) ⇒ Object
- public
-
Includes actions from the given pipeline.
59 60 61 62 63 64 65 |
# File 'lib/core/pipeline/callable.rb', line 59 def include(pipeline) if (pipeline.is_a?(Class) || pipeline.is_a?(Module)) && pipeline.ancestors.include?(Is::Pipeline) @actions.concat(pipeline.pipeline.actions) else raise ArgumentError, "expected a pipeline" end end |
#skip(name) ⇒ Object
- public
-
Skips the given action.
40 41 42 |
# File 'lib/core/pipeline/callable.rb', line 40 def skip(name) @skipped << name.to_sym end |
#use(pipeline) ⇒ Object
- public
-
Replaces existing actions with actions from the given pipeline.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/core/pipeline/callable.rb', line 46 def use(pipeline) if (pipeline.is_a?(Class) || pipeline.is_a?(Module)) && pipeline.ancestors.include?(Is::Pipeline) @mutex.synchronize do @actions.clear @actions.concat(pipeline.pipeline.actions) end else raise ArgumentError, "expected a pipeline" end end |