Class: Plumb::Pipeline
Defined Under Namespace
Classes: AroundStep
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Composable
#>>, #[], #as_node, #build, #check, #defer, #generate, included, #invalid, #invoke, #match, #metadata, #not, #pipeline, #policy, #static, #to_json_schema, #to_s, #transform, #value, wrap, #|
Methods included from Callable
#parse, #resolve
Constructor Details
#initialize(type: Types::Any, freeze_after: true, &setup) ⇒ Pipeline
40
41
42
43
44
45
46
47
48
|
# File 'lib/plumb/pipeline.rb', line 40
def initialize(type: Types::Any, freeze_after: true, &setup)
@type = type
@children = [type].freeze
@around_blocks = self.class.around_blocks.dup
return unless block_given?
configure(&setup)
freeze if freeze_after
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
38
39
40
|
# File 'lib/plumb/pipeline.rb', line 38
def children
@children
end
|
Class Method Details
.around(callable = nil, &block) ⇒ Object
27
28
29
30
|
# File 'lib/plumb/pipeline.rb', line 27
def around(callable = nil, &block)
around_blocks << (callable || block)
self
end
|
.around_blocks ⇒ Object
23
24
25
|
# File 'lib/plumb/pipeline.rb', line 23
def around_blocks
@around_blocks ||= []
end
|
.inherited(subclass) ⇒ Object
32
33
34
35
|
# File 'lib/plumb/pipeline.rb', line 32
def inherited(subclass)
around_blocks.each { |block| subclass.around(block) }
super
end
|
Instance Method Details
#around(callable = nil, &block) ⇒ Object
67
68
69
70
|
# File 'lib/plumb/pipeline.rb', line 67
def around(callable = nil, &block)
@around_blocks << (callable || block)
self
end
|
#call(result) ⇒ Object
50
51
52
|
# File 'lib/plumb/pipeline.rb', line 50
def call(result)
@type.call(result)
end
|
#step(callable = nil, &block) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/plumb/pipeline.rb', line 54
def step(callable = nil, &block)
callable ||= block
unless is_a_step?(callable)
raise ArgumentError,
"#step expects an interface #call(Result) Result, but got #{callable.inspect}"
end
callable = prepare_step(callable)
callable = @around_blocks.reverse.reduce(callable) { |cl, bl| AroundStep.new(cl, bl) } if @around_blocks.any?
@type >>= callable
self
end
|