class SideBoom::Pipeline

Attributes

sink[R]
stages[R]

Public Class Methods

define(sink = $stdout, &block) click to toggle source
# 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
new(sink) click to toggle source
# File lib/side_boom/pipeline.rb, line 21
def initialize(sink)
  @sink = sink
  @stages = []
end

Public Instance Methods

stage(name, &block) click to toggle source
# 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!() click to toggle source
# 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

Private Instance Methods

to_hash() click to toggle source
# File lib/side_boom/pipeline.rb, line 42
def to_hash
  hsh = {}
  hsh['stages'] = @stages.map(&:name)

  @stages.each { |stage| hsh.merge!(stage.to_hash) }
  hsh
end
to_yaml() click to toggle source
# File lib/side_boom/pipeline.rb, line 50
def to_yaml
  to_hash.to_yaml
end