stages 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/stages/unique.rb +10 -9
- data/stages.gemspec +2 -2
- data/test/test_stages.rb +22 -3
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/lib/stages/unique.rb
CHANGED
@@ -2,18 +2,19 @@ require 'set'
|
|
2
2
|
|
3
3
|
module Stages
|
4
4
|
class Unique < Stage
|
5
|
-
def
|
6
|
-
@
|
5
|
+
def initialize(options = { })
|
6
|
+
@prefetch = options[:prefetch]
|
7
7
|
super()
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
output
|
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
|
data/stages.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "stages"
|
8
|
-
s.version = "0.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-
|
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 = [
|
data/test/test_stages.rb
CHANGED
@@ -95,13 +95,31 @@ class TestStages < MiniTest::Unit::TestCase
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
|
99
|
-
|
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
|
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.
|
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-
|
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:
|
78
|
+
hash: 2855126924498756477
|
79
79
|
segments:
|
80
80
|
- 0
|
81
81
|
version: "0"
|