stages 0.3.3 → 0.3.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -2,18 +2,19 @@ require 'set'
2
2
 
3
3
  module Stages
4
4
  class Unique < Stage
5
- def initialize_loop
6
- @set = Set.new
5
+ def initialize(options = { })
6
+ @prefetch = options[:prefetch]
7
7
  super()
8
8
  end
9
9
 
10
- def die
11
- @set = Set.new
12
- super()
13
- end
14
-
15
- def handle_value(value)
16
- output value if @set.add? value.hash
10
+ def process
11
+ set = Set.new
12
+ while i = input
13
+ added = set.add? i
14
+ handle_value i if added && !@prefetch
15
+ end
16
+ set.each{ |x| output x} if @prefetch
17
+ set = nil
17
18
  end
18
19
  end
19
20
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "stages"
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["The Justice Eight"]
12
- s.date = "2012-03-12"
12
+ s.date = "2012-04-02"
13
13
  s.description = "pipeline builder"
14
14
  s.email = "support@igodigital.com"
15
15
  s.extra_rdoc_files = [
@@ -95,13 +95,31 @@ class TestStages < MiniTest::Unit::TestCase
95
95
  end
96
96
  end
97
97
 
98
- test 'unique' do
99
- pipeline = Each.new('abcadefbega'){ |x| x.chars} | Unique.new
98
+
99
+ test 'unique-jit' do
100
+ order = []
101
+ pipeline = Each.new('abcadefbega'){ |x| x.chars} |
102
+ Map.new{ |x| order << 'a'; x} | Unique.new|
103
+ Map.new{ |x| order << 'b'; x}
104
+ results = []
105
+ while r = pipeline.run
106
+ results << r
107
+ end
108
+ assert_equal(%w(a b c d e f g), results)
109
+ assert_equal(%w(a b a b a b a a b a b a b a a a b a), order)
110
+ end
111
+
112
+ test 'unique-prefetch' do
113
+ order = []
114
+ pipeline = Each.new('abcadefbega'){ |x| x.chars} |
115
+ Map.new{ |x| order << 'a'; x} | Unique.new(prefetch: true) |
116
+ Map.new{ |x| order << 'b'; x}
100
117
  results = []
101
118
  while r = pipeline.run
102
119
  results << r
103
120
  end
104
121
  assert_equal(%w(a b c d e f g), results)
122
+ assert_equal(['a']*11 + ['b']*7, order)
105
123
  end
106
124
 
107
125
  test 'exhaust' do
@@ -114,7 +132,8 @@ class TestStages < MiniTest::Unit::TestCase
114
132
  assert_equal(3, pipeline.run)
115
133
  end
116
134
 
117
- test 'cache' do order = []
135
+ test 'cache' do
136
+ order = []
118
137
  pipeline = Each.new([1, 3, 2, 3, 2, 1]) | Map.new{|x| order << 'a'; x} | Cache.new | Map.new{|x| order << 'b'; x} | Exhaust.new
119
138
  assert_equal([1, 3, 2, 3, 2, 1], pipeline.run)
120
139
  assert_equal(%w(a a a a a a b b b b b b), order)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: stages
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.3
5
+ version: 0.3.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - The Justice Eight
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-03-12 00:00:00 Z
13
+ date: 2012-04-02 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -75,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- hash: 3232589023381470153
78
+ hash: 2855126924498756477
79
79
  segments:
80
80
  - 0
81
81
  version: "0"