Class: Linepipe::Process
- Inherits:
-
Object
show all
- Includes:
- DSL
- Defined in:
- lib/linepipe/process.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from DSL
#data, #expect, #setup, #step
Constructor Details
#initialize(io = STDOUT) ⇒ Process
Returns a new instance of Process.
8
9
10
11
12
13
14
15
|
# File 'lib/linepipe/process.rb', line 8
def initialize(io=STDOUT)
@data = []
@steps = []
@setup = nil
@output = nil
@expectations = []
@io = io
end
|
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
6
7
8
|
# File 'lib/linepipe/process.rb', line 6
def output
@output
end
|
#steps ⇒ Object
Returns the value of attribute steps.
6
7
8
|
# File 'lib/linepipe/process.rb', line 6
def steps
@steps
end
|
Instance Method Details
#[](name) ⇒ Object
17
18
19
|
# File 'lib/linepipe/process.rb', line 17
def [](name)
steps.detect { |s| s.name == name }
end
|
#benchmark(iterations) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/linepipe/process.rb', line 44
def benchmark(iterations)
require 'benchmark'
require 'stringio'
run_setup
label_length = steps.map(&:name).map(&:length).max
out = $stdout
$stdout = stringio = StringIO.new
Benchmark.bmbm(label_length) do |x|
@output = steps.reduce(initial_data) { |d, step|
result = step.apply(d)
x.report(step.name) { iterations.times { step.apply(d) } }
result
}
end
io.puts stringio.string
ensure
$stdout = out
end
|
#develop ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/linepipe/process.rb', line 26
def develop
run_setup
@output = steps.to_enum.with_index.reduce(initial_data) { |d, (step, idx)|
log "Stage #{idx}", step.name
log "\tInput", d
step.apply(d).tap do |result|
log "\tOutput", result
step.verify_expectations(result).each do |expectation|
log "\t\t#{expectation.name}: #{expectation.status}"
end
end
}
if expectations.all? { |exp| exp.successful?(output) }
log "Expect", "SUCCESS"
end
end
|
#run ⇒ Object
21
22
23
24
|
# File 'lib/linepipe/process.rb', line 21
def run
run_setup
@output = steps.reduce(initial_data) { |d, step| step.apply(d) }
end
|