stages 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/stages/feeder.rb +20 -0
- data/lib/stages/wrap.rb +5 -5
- data/lib/sugar.rb +4 -0
- data/stages.gemspec +3 -2
- data/test/test_stages.rb +14 -0
- data/test/test_syntax.rb +14 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Stages
|
2
|
+
class Feeder < Stage
|
3
|
+
def initialize
|
4
|
+
@values = []
|
5
|
+
super()
|
6
|
+
end
|
7
|
+
|
8
|
+
def <<(value)
|
9
|
+
@values.push(value)
|
10
|
+
reset if done?
|
11
|
+
end
|
12
|
+
|
13
|
+
def process
|
14
|
+
loop do
|
15
|
+
break if @values.empty?
|
16
|
+
handle_value @values.shift
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/stages/wrap.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Stages
|
2
2
|
class Wrap < Stage
|
3
3
|
def initialize(pipeline, *args)
|
4
|
-
@
|
4
|
+
@feeder = Feeder.new
|
5
|
+
@pipeline = @feeder | pipeline
|
5
6
|
@output_style = :hash
|
6
7
|
unless args.empty?
|
7
8
|
if args.include? :array
|
@@ -23,16 +24,15 @@ module Stages
|
|
23
24
|
def process
|
24
25
|
while !source_empty?
|
25
26
|
value = input
|
26
|
-
|
27
|
+
@feeder << value
|
27
28
|
results = []
|
28
|
-
while
|
29
|
-
v =
|
29
|
+
while !@pipeline.done?
|
30
|
+
v = @pipeline.run
|
30
31
|
@output_style == :each ? output(v) : results << v
|
31
32
|
end
|
32
33
|
results = results.first if @aggregated
|
33
34
|
output results if @output_style == :array
|
34
35
|
output({ value => results}) if @output_style == :hash
|
35
|
-
@pipeline.drop_leftmost!
|
36
36
|
@pipeline.reset
|
37
37
|
end
|
38
38
|
@pipeline.reset
|
data/lib/sugar.rb
CHANGED
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.4.
|
8
|
+
s.version = "0.4.1"
|
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-04-
|
12
|
+
s.date = "2012-04-16"
|
13
13
|
s.description = "pipeline builder"
|
14
14
|
s.email = "support@igodigital.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/stages/emit.rb",
|
33
33
|
"lib/stages/exhaust.rb",
|
34
34
|
"lib/stages/exhaust_count.rb",
|
35
|
+
"lib/stages/feeder.rb",
|
35
36
|
"lib/stages/map.rb",
|
36
37
|
"lib/stages/select.rb",
|
37
38
|
"lib/stages/unique.rb",
|
data/test/test_stages.rb
CHANGED
@@ -65,6 +65,20 @@ class TestStages < MiniTest::Unit::TestCase
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
test 'feeder' do
|
69
|
+
feeder = Feeder.new
|
70
|
+
pipeline = feeder | Map.new{ |x| x*2}
|
71
|
+
assert feeder.done?
|
72
|
+
feeder << 1
|
73
|
+
feeder << 2
|
74
|
+
assert_equal(2, pipeline.run)
|
75
|
+
assert_equal(4, pipeline.run)
|
76
|
+
assert feeder.done?
|
77
|
+
feeder << 3
|
78
|
+
assert_equal(6, pipeline.run)
|
79
|
+
assert pipeline.done?
|
80
|
+
end
|
81
|
+
|
68
82
|
test 'nil makes it through' do
|
69
83
|
pipeline = Each.new([1, 2, nil, 4]) | Map.new{ |x| x.nil? ? x : x*2} | Exhaust.new
|
70
84
|
result = pipeline.run
|
data/test/test_syntax.rb
CHANGED
@@ -38,4 +38,18 @@ class TestSyntax < MiniTest::Unit::TestCase
|
|
38
38
|
assert_equal([1, 3, 2, 3, 2, 1], pipeline.run)
|
39
39
|
assert_equal(%w(a a a a a a b b b b b b), order)
|
40
40
|
end
|
41
|
+
|
42
|
+
test 'feeder' do
|
43
|
+
f = feeder
|
44
|
+
pipeline = f | map{ |x| x*2}
|
45
|
+
assert feeder.done?
|
46
|
+
f << 1
|
47
|
+
f << 2
|
48
|
+
assert_equal(2, pipeline.run)
|
49
|
+
assert_equal(4, pipeline.run)
|
50
|
+
assert f.done?
|
51
|
+
f << 3
|
52
|
+
assert_equal(6, pipeline.run)
|
53
|
+
assert pipeline.done?
|
54
|
+
end
|
41
55
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: stages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.1
|
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-04-
|
13
|
+
date: 2012-04-16 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/stages/emit.rb
|
49
49
|
- lib/stages/exhaust.rb
|
50
50
|
- lib/stages/exhaust_count.rb
|
51
|
+
- lib/stages/feeder.rb
|
51
52
|
- lib/stages/map.rb
|
52
53
|
- lib/stages/select.rb
|
53
54
|
- lib/stages/unique.rb
|
@@ -71,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
72
|
requirements:
|
72
73
|
- - ">="
|
73
74
|
- !ruby/object:Gem::Version
|
74
|
-
hash:
|
75
|
+
hash: 3910381420948442962
|
75
76
|
segments:
|
76
77
|
- 0
|
77
78
|
version: "0"
|