linepipe 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +5 -0
- data/README.md +7 -5
- data/lib/linepipe/dsl.rb +1 -1
- data/lib/linepipe/expectation.rb +4 -6
- data/lib/linepipe/process.rb +12 -8
- data/lib/linepipe/version.rb +1 -1
- data/linepipe.gemspec +1 -0
- data/spec/pipeline/expectation_spec.rb +10 -3
- metadata +21 -4
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
A tool to aid in processing data in a pipeline, making every step easily
|
4
4
|
testable and benchmarkable.
|
5
5
|
|
6
|
+
[](https://travis-ci.org/wimdu/linepipe)
|
7
|
+
|
6
8
|
## Installation
|
7
9
|
|
8
10
|
Add this line to your application's Gemfile:
|
@@ -23,7 +25,7 @@ Linepipe's DSL consists of 4 different parts:
|
|
23
25
|
|
24
26
|
* `setup`: Optional setup that will be run at the beginning.
|
25
27
|
* `data`: The input data.
|
26
|
-
* `
|
28
|
+
* `step`: As many of these as you want will conform the steps of your
|
27
29
|
algorithm.
|
28
30
|
* `expect`: In development mode, each of these will be run against your final
|
29
31
|
output data to ensure its conformity with your expectations.
|
@@ -33,16 +35,16 @@ While developing a processing algorithm, `Linepipe.develop` is your friend. Each
|
|
33
35
|
`expect` block will be run against the final output to ensure that it works.
|
34
36
|
|
35
37
|
```ruby
|
36
|
-
linepipe = Linepipe.
|
38
|
+
linepipe = Linepipe.develop do
|
37
39
|
data {
|
38
40
|
%w(foo bar baz)
|
39
41
|
}
|
40
42
|
|
41
|
-
|
43
|
+
step("Upcasing") { |data|
|
42
44
|
data.map(&:upcase)
|
43
45
|
}
|
44
46
|
|
45
|
-
|
47
|
+
step("Reversing") { |data|
|
46
48
|
data.reverse
|
47
49
|
}
|
48
50
|
|
@@ -51,7 +53,7 @@ linepipe = Linepipe.run do
|
|
51
53
|
}
|
52
54
|
end
|
53
55
|
|
54
|
-
linepipe.
|
56
|
+
linepipe.output # => %W(BAZ BAR FOO)
|
55
57
|
```
|
56
58
|
|
57
59
|
Once you're comfortable with your algorithm, just change your call to
|
data/lib/linepipe/dsl.rb
CHANGED
data/lib/linepipe/expectation.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
module Linepipe
|
2
2
|
class Expectation
|
3
|
-
def initialize(msg="Assertion failed",
|
4
|
-
@msg
|
5
|
-
@io = io
|
6
|
-
@block = block
|
3
|
+
def initialize(msg = "Assertion failed", log_method = nil, &block)
|
4
|
+
@msg, @log_method, @block = msg, log_method, block
|
7
5
|
end
|
8
6
|
|
9
7
|
def successful?(data)
|
10
8
|
if !block.call(data)
|
11
|
-
|
9
|
+
log_method.call("Expectation", "Failed at #{block.source_location.join(':')} (#{msg})")
|
12
10
|
return false
|
13
11
|
end
|
14
12
|
true
|
15
13
|
end
|
16
14
|
|
17
15
|
private
|
18
|
-
attr_reader :block, :msg, :
|
16
|
+
attr_reader :block, :msg, :log_method
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
data/lib/linepipe/process.rb
CHANGED
@@ -26,15 +26,15 @@ module Linepipe
|
|
26
26
|
def develop
|
27
27
|
run_setup
|
28
28
|
@output = steps.to_enum.with_index.reduce(initial_data) { |d, (step, idx)|
|
29
|
-
|
30
|
-
|
29
|
+
log "Stage #{idx}", step.name
|
30
|
+
log "Input", d
|
31
31
|
step.apply(d).tap do |r|
|
32
|
-
|
32
|
+
log "Output", r
|
33
33
|
end
|
34
34
|
}
|
35
35
|
|
36
36
|
if expectations.all? { |exp| exp.successful?(output) }
|
37
|
-
|
37
|
+
log "Expect", "SUCCESS"
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -66,15 +66,19 @@ module Linepipe
|
|
66
66
|
private
|
67
67
|
attr_reader :expectations, :io
|
68
68
|
|
69
|
+
def log(topic, msg = "")
|
70
|
+
io.puts "\n[Linepipe] #{topic} #{msg}\n"
|
71
|
+
end
|
72
|
+
|
69
73
|
def run_setup
|
70
74
|
@setup.call if @setup
|
71
75
|
end
|
72
76
|
|
73
77
|
def initial_data
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
@data.call.tap do |data|
|
79
|
+
if data.nil?
|
80
|
+
log("Warn", "You need to specify an initial data set")
|
81
|
+
end
|
78
82
|
end
|
79
83
|
end
|
80
84
|
|
data/lib/linepipe/version.rb
CHANGED
data/linepipe.gemspec
CHANGED
@@ -5,16 +5,23 @@ require 'stringio'
|
|
5
5
|
module Linepipe
|
6
6
|
describe Expectation, '#successful?' do
|
7
7
|
let(:io) { StringIO.new }
|
8
|
+
let(:log) { double('Log') }
|
9
|
+
|
10
|
+
before do
|
11
|
+
log.stub(:call)
|
12
|
+
end
|
8
13
|
|
9
14
|
describe 'when it fails' do
|
10
15
|
let(:expectation) do
|
11
|
-
Expectation.new('Failure message',
|
16
|
+
Expectation.new('Failure message', log) { false }
|
12
17
|
end
|
13
18
|
|
14
19
|
it 'prints the message to the output' do
|
20
|
+
log.should_receive(:call) do |topic, msg|
|
21
|
+
expect(topic).to match(/expectation/i)
|
22
|
+
expect(msg).to match(/Failure message/)
|
23
|
+
end
|
15
24
|
expectation.successful?(%w(some data))
|
16
|
-
expect(io.string).to match(/expectation_spec/)
|
17
|
-
expect(io.string).to match(/Failure message/)
|
18
25
|
end
|
19
26
|
|
20
27
|
it 'returns false' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linepipe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: Process data one step at a time.
|
31
47
|
email:
|
32
48
|
- josep.bach@wimdu.com
|
@@ -35,6 +51,7 @@ extensions: []
|
|
35
51
|
extra_rdoc_files: []
|
36
52
|
files:
|
37
53
|
- .gitignore
|
54
|
+
- .travis.yml
|
38
55
|
- Gemfile
|
39
56
|
- LICENSE.txt
|
40
57
|
- README.md
|
@@ -66,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
83
|
version: '0'
|
67
84
|
segments:
|
68
85
|
- 0
|
69
|
-
hash:
|
86
|
+
hash: 3429959400891049712
|
70
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
88
|
none: false
|
72
89
|
requirements:
|
@@ -75,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
92
|
version: '0'
|
76
93
|
segments:
|
77
94
|
- 0
|
78
|
-
hash:
|
95
|
+
hash: 3429959400891049712
|
79
96
|
requirements: []
|
80
97
|
rubyforge_project:
|
81
98
|
rubygems_version: 1.8.23
|