linepipe 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - rbx-19mode
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
+ [![Build Status](https://travis-ci.org/wimdu/linepipe.png?branch=master)](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
- * `process`: As many of these as you want will conform the steps of your
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.run do
38
+ linepipe = Linepipe.develop do
37
39
  data {
38
40
  %w(foo bar baz)
39
41
  }
40
42
 
41
- process("Upcasing") { |data|
43
+ step("Upcasing") { |data|
42
44
  data.map(&:upcase)
43
45
  }
44
46
 
45
- process("Reversing") { |data|
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.result # => %W(BAZ BAR FOO)
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
@@ -16,7 +16,7 @@ module Linepipe
16
16
  end
17
17
 
18
18
  def expect(msg=nil, &block)
19
- @expectations << Expectation.new(msg, io, &block)
19
+ @expectations << Expectation.new(msg, method(:log), &block)
20
20
  end
21
21
  end
22
22
  end
@@ -1,21 +1,19 @@
1
1
  module Linepipe
2
2
  class Expectation
3
- def initialize(msg="Assertion failed", io=STDOUT, &block)
4
- @msg = 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
- io.puts "Expectation failed at #{block.source_location.join(':')} (#{msg})"
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, :io
16
+ attr_reader :block, :msg, :log_method
19
17
  end
20
18
  end
21
19
 
@@ -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
- io.puts "Stage #{idx} #{step.name}"
30
- io.puts "Input: #{d}"
29
+ log "Stage #{idx}", step.name
30
+ log "Input", d
31
31
  step.apply(d).tap do |r|
32
- io.puts "Output: #{r}"
32
+ log "Output", r
33
33
  end
34
34
  }
35
35
 
36
36
  if expectations.all? { |exp| exp.successful?(output) }
37
- io.puts "SUCCESS!"
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
- if @data.is_a?(Proc)
75
- @data.call
76
- else
77
- puts "[Linepipe] Warn: You need to specify an initial data set"
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
 
@@ -1,3 +1,3 @@
1
1
  module Linepipe
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/linepipe.gemspec CHANGED
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_development_dependency 'rspec'
21
+ gem.add_development_dependency 'rake'
21
22
  end
@@ -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', io) { false }
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.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-14 00:00:00.000000000 Z
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: 1238965093489806578
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: 1238965093489806578
95
+ hash: 3429959400891049712
79
96
  requirements: []
80
97
  rubyforge_project:
81
98
  rubygems_version: 1.8.23