Class: PiecePipe::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/piece_pipe/pipeline.rb

Instance Method Summary collapse

Constructor Details

#initializePipeline

Returns a new instance of Pipeline.



3
4
5
# File 'lib/piece_pipe/pipeline.rb', line 3

def initialize
  @latest_source = nil
end

Instance Method Details

#assembly_step(step) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/piece_pipe/pipeline.rb', line 28

def assembly_step(step)
  case step
  when Class
    step = step.new # If the arg is a Class, instantiate it
  when Method
    step = MethodAssemblyStep.new(step)
  end
  add_step step
end

#collect(key) ⇒ Object



53
54
55
# File 'lib/piece_pipe/pipeline.rb', line 53

def collect(key)
  step(Collector.new(key))
end

#debug(opts) ⇒ Object



49
50
51
# File 'lib/piece_pipe/pipeline.rb', line 49

def debug(opts)
  step(DebugStep.new(opts))
end

#input(item) ⇒ Object



13
14
15
16
# File 'lib/piece_pipe/pipeline.rb', line 13

def input(item)
  source [item]
  self
end

#resultObject



57
58
59
# File 'lib/piece_pipe/pipeline.rb', line 57

def result
  to_enum.first
end

#source(source) ⇒ Object



7
8
9
10
11
# File 'lib/piece_pipe/pipeline.rb', line 7

def source(source)
  raise "Source already set to #{@latest_source.inspect}" unless @latest_source.nil?
  @latest_source = source
  self
end

#step(step) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/piece_pipe/pipeline.rb', line 18

def step(step)
  case step
  when Class
    step = step.new # If the arg is a Class, instantiate it
  when Method
    step = MethodStep.new(step)
  end
  add_step step
end

#tap(&block) ⇒ Object



45
46
47
# File 'lib/piece_pipe/pipeline.rb', line 45

def tap(&block)
  step(TapStep.new(&block))
end

#to_aObject



66
67
68
# File 'lib/piece_pipe/pipeline.rb', line 66

def to_a
  to_enum.to_a
end

#to_enumObject Also known as: smoke



61
62
63
# File 'lib/piece_pipe/pipeline.rb', line 61

def to_enum
  @latest_source.to_enum
end