Class: SideBoom::Pipeline

Inherits:
Object
  • Object
show all
Includes:
Attributes
Defined in:
lib/side_boom/pipeline.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes

array_attribute, #attributes, boolean_attribute, string_attribute

Constructor Details

#initialize(sink) ⇒ Pipeline

Returns a new instance of Pipeline.



21
22
23
24
# File 'lib/side_boom/pipeline.rb', line 21

def initialize(sink)
  @sink = sink
  @stages = []
end

Instance Attribute Details

#sinkObject (readonly)

Returns the value of attribute sink.



19
20
21
# File 'lib/side_boom/pipeline.rb', line 19

def sink
  @sink
end

#stagesObject (readonly)

Returns the value of attribute stages.



19
20
21
# File 'lib/side_boom/pipeline.rb', line 19

def stages
  @stages
end

Class Method Details

.define(sink = $stdout, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/side_boom/pipeline.rb', line 8

def define(sink = $stdout, &block)
  sink = File.open(sink, 'w+') if sink.is_a?(String)

  SideBoom::Context.in(self) do
    pipeline = new(sink)
    pipeline.instance_eval(&block)
    pipeline.write!
  end
end

Instance Method Details

#stage(name, &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/side_boom/pipeline.rb', line 26

def stage(name, &block)
  SideBoom::Context.in(self) do
    new_stage = SideBoom::Stage.new(name)
    new_stage.instance_eval(&block) if block_given?
    @stages << new_stage
  end
end

#write!Object



34
35
36
37
38
# File 'lib/side_boom/pipeline.rb', line 34

def write!
  content = "# Generated by SideBoom\n" + to_yaml
  @sink.write(content)
  @sink.close if @sink.is_a?(File)
end