Class: PhaseShift::Builder
- Inherits:
-
Object
- Object
- PhaseShift::Builder
- Defined in:
- lib/phase_shift/builder.rb
Overview
Create a pipeline by building up stages
Instance Attribute Summary collapse
-
#stages ⇒ Object
readonly
Returns the value of attribute stages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(default_stage = nil, &block) ⇒ Builder
constructor
A new instance of Builder.
- #pipeline ⇒ Object
- #run ⇒ Object
- #use(stage, *args) ⇒ Object
Constructor Details
#initialize(default_stage = nil, &block) ⇒ Builder
Returns a new instance of Builder.
12 13 14 15 16 |
# File 'lib/phase_shift/builder.rb', line 12 def initialize(default_stage = nil, &block) @default_stage = default_stage || proc { [] } @stages = [] instance_eval(&block) if block_given? end |
Instance Attribute Details
#stages ⇒ Object (readonly)
Returns the value of attribute stages.
4 5 6 |
# File 'lib/phase_shift/builder.rb', line 4 def stages @stages end |
Class Method Details
.parse_file(config, file = '(phase_shift)') ⇒ Object
6 7 8 9 10 |
# File 'lib/phase_shift/builder.rb', line 6 def self.parse_file(config, file = '(phase_shift)') builder_script = ::File.read(config) code = "PhaseShift::Builder.new {\n" + builder_script + "\n}.pipeline" eval code, TOPLEVEL_BINDING, file, 0 end |
Instance Method Details
#pipeline ⇒ Object
22 23 24 |
# File 'lib/phase_shift/builder.rb', line 22 def pipeline stages.inject(@default_stage) { |a, e| e[a] } end |
#run ⇒ Object
26 27 28 |
# File 'lib/phase_shift/builder.rb', line 26 def run pipeline.call end |
#use(stage, *args) ⇒ Object
18 19 20 |
# File 'lib/phase_shift/builder.rb', line 18 def use(stage, *args) @stages << proc { |pipeline| stage.new(pipeline, *args) } end |