stages 1.0.1 → 1.1.1

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.
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ script: "rake test"
6
+ before_install:
7
+ - gem update --system 1.8.25
8
+ - gem --version
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/iGoDigital-LLC/stages.png)](https://travis-ci.org/iGoDigital-LLC/stages)
2
+
1
3
  Stages
2
4
  ------
3
5
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.1
@@ -1,5 +1,6 @@
1
1
  module Stages
2
2
  class Stage
3
+ include Enumerable
3
4
  attr_accessor :source
4
5
 
5
6
  def initialize(&block)
@@ -56,6 +57,18 @@ module Stages
56
57
  end
57
58
  end
58
59
 
60
+ def to_enum
61
+ Enumerator.new do |y|
62
+ while !done?
63
+ y << run
64
+ end
65
+ end
66
+ end
67
+
68
+ def each(&block)
69
+ to_enum.each(&block)
70
+ end
71
+
59
72
  def handle_value(value)
60
73
  output value
61
74
  end
@@ -9,9 +9,8 @@ module Stages
9
9
  def process
10
10
  if @things
11
11
  process_things
12
- else
13
- process_inputs
14
12
  end
13
+ process_inputs
15
14
  end
16
15
 
17
16
  def process_inputs
@@ -19,7 +18,7 @@ module Stages
19
18
  v = input
20
19
  v = @block.call(v) if @block
21
20
  v.each do |v|
22
- output v
21
+ handle_value v
23
22
  end
24
23
  end
25
24
  end
@@ -0,0 +1,21 @@
1
+ module Stages
2
+ class Limit < Stage
3
+ def initialize(allowed)
4
+ @allowed = allowed
5
+ @sent = 0
6
+ super()
7
+ end
8
+
9
+ def process
10
+ while @sent < @allowed
11
+ handle_value input
12
+ @sent += 1
13
+ end
14
+ end
15
+
16
+ def reset
17
+ @sent = 0
18
+ super()
19
+ end
20
+ end
21
+ end
@@ -43,5 +43,9 @@ module Stages
43
43
  def feeder(*args, &block)
44
44
  Feeder.new(*args, &block)
45
45
  end
46
+
47
+ def limit(*args, &block)
48
+ Limit.new(*args, &block)
49
+ end
46
50
  end
47
51
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "stages"
8
- s.version = "1.0.1"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan D Acuff"]
12
- s.date = "2013-03-01"
12
+ s.date = "2013-08-21"
13
13
  s.description = "pipeline builder"
14
14
  s.email = "support@igodigital.com"
15
15
  s.extra_rdoc_files = [
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  ]
18
18
  s.files = [
19
19
  ".autotest",
20
+ ".travis.yml",
20
21
  "Gemfile",
21
22
  "Gemfile.lock",
22
23
  "README.md",
@@ -33,6 +34,7 @@ Gem::Specification.new do |s|
33
34
  "lib/stages/exhaust.rb",
34
35
  "lib/stages/exhaust_count.rb",
35
36
  "lib/stages/feeder.rb",
37
+ "lib/stages/limit.rb",
36
38
  "lib/stages/map.rb",
37
39
  "lib/stages/select.rb",
38
40
  "lib/stages/unique.rb",
@@ -61,9 +61,30 @@ class TestPipeline < MiniTest::Unit::TestCase
61
61
  assert_equal(2, pipeline.run)
62
62
  end
63
63
 
64
+ test 'reset resets limit' do
65
+ pipeline = Each.new([1, 2, 3, 4, 5]) | Limit.new(2)
66
+ assert_equal(1, pipeline.run)
67
+ assert_equal(2, pipeline.run)
68
+ pipeline.reset
69
+ assert_equal(1, pipeline.run)
70
+ assert_equal(2, pipeline.run)
71
+ assert_equal(:stages_eos, pipeline.run)
72
+ end
73
+
64
74
  test 'nil stages are skipped/no-ops' do
65
75
  pipeline = Evens.new | nil | Select.new{ |x| x > 3}
66
76
  assert_equal(4, pipeline.run)
67
77
  assert_equal(6, pipeline.run)
68
78
  end
79
+
80
+ test "pipeline as enum" do
81
+ pipeline = Each.new([1,2,3,4,5]) | Select.new{ |x| x % 2 == 0}
82
+ output = pipeline.map{ |x| x }
83
+ assert_equal([2,4], output)
84
+
85
+ pipeline.reset
86
+ pipeline.each_slice(2) do |thing|
87
+ assert_equal([2, 4], thing)
88
+ end
89
+ end
69
90
  end
@@ -164,6 +164,27 @@ class TestStages < MiniTest::Unit::TestCase
164
164
  assert pipeline.done?
165
165
  end
166
166
 
167
+ test 'each with input and incoming data prepends given data' do
168
+ pipeline = Emit.new([1,2,3]) | Each.new([4,5,6]) | Exhaust.new
169
+ assert_equal([4,5,6,1,2,3], pipeline.run)
170
+ end
171
+
172
+ test 'limit stage only ticks X times' do
173
+ pipeline = Each.new([1,2,3,4,4]) | Limit.new(2) | Exhaust.new
174
+ assert_equal([1,2], pipeline.run)
175
+ end
176
+
177
+ test "stage as enum" do
178
+ pipeline = Each.new([1,2,3,4,5])
179
+ output = pipeline.to_enum.map{ |x| x }
180
+ assert_equal([1,2,3,4,5], output)
181
+
182
+ pipeline.reset
183
+ output = []
184
+ pipeline.to_enum.each_slice(2){ |x| output << x }
185
+ assert_equal([[1,2],[3,4],[5]], output)
186
+ end
187
+
167
188
  def sing
168
189
  { :do => 'doe a deer a female deer',
169
190
  :re => 'ray a drop of golden sun',
@@ -52,4 +52,9 @@ class TestSyntax < MiniTest::Unit::TestCase
52
52
  assert_equal(6, pipeline.run)
53
53
  assert pipeline.done?
54
54
  end
55
+
56
+ test 'limit' do
57
+ pipeline = each([1,2,3]) | limit(2) | run_until_exhausted
58
+ assert_equal([1, 2], pipeline.run)
59
+ end
55
60
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: stages
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.1
5
+ version: 1.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nathan D Acuff
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-03-01 00:00:00 Z
13
+ date: 2013-08-21 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -33,6 +33,7 @@ extra_rdoc_files:
33
33
  - README.md
34
34
  files:
35
35
  - .autotest
36
+ - .travis.yml
36
37
  - Gemfile
37
38
  - Gemfile.lock
38
39
  - README.md
@@ -49,6 +50,7 @@ files:
49
50
  - lib/stages/exhaust.rb
50
51
  - lib/stages/exhaust_count.rb
51
52
  - lib/stages/feeder.rb
53
+ - lib/stages/limit.rb
52
54
  - lib/stages/map.rb
53
55
  - lib/stages/select.rb
54
56
  - lib/stages/unique.rb
@@ -72,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
74
  requirements:
73
75
  - - ">="
74
76
  - !ruby/object:Gem::Version
75
- hash: 152651317607917436
77
+ hash: 730254182358055923
76
78
  segments:
77
79
  - 0
78
80
  version: "0"