stages 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.5
1
+ 1.2.0
@@ -1,7 +1,7 @@
1
1
  module Stages
2
2
  class Stage
3
3
  include Enumerable
4
- attr_accessor :source
4
+ attr_accessor :source, :invocations
5
5
 
6
6
  def initialize(&block)
7
7
  @block = block
@@ -9,6 +9,7 @@ module Stages
9
9
  end
10
10
 
11
11
  def initialize_loop
12
+ @invocations = 0
12
13
  @done = false
13
14
  @cached_value = :stages_empty_cache
14
15
  @fiber_delegate = Fiber.new do
@@ -27,6 +28,11 @@ module Stages
27
28
  @fiber_delegate.resume
28
29
  end
29
30
 
31
+ def run_all
32
+ run until done?
33
+ invocations
34
+ end
35
+
30
36
  def done?
31
37
  return true if @done
32
38
  return false if @cached_value != :stages_empty_cache
@@ -82,11 +88,12 @@ module Stages
82
88
  end
83
89
 
84
90
  def output(value)
91
+ @invocations += 1 unless value == :stages_eos
85
92
  Fiber.yield value
86
93
  end
87
94
 
88
95
  def |(other)
89
- return self if other.nil?
96
+ return self if other.nil? || other.is_a?(Noop)
90
97
  other.root_source.source = self
91
98
  other
92
99
  end
@@ -1,4 +1,4 @@
1
1
  require "#{File.dirname(__FILE__)}/stage_base"
2
- Dir["#{File.dirname(__FILE__)}/stages/*.rb"].each { |file| require file.gsub(".rb", "")}
2
+ Dir["#{File.dirname(__FILE__)}/stages/*.rb"].each { |file| require file.gsub(/.rb$/, "")}
3
3
  require "#{File.dirname(__FILE__)}/sugar"
4
4
 
@@ -0,0 +1,7 @@
1
+ module Stages
2
+ class Noop < Stage
3
+ def |(other)
4
+ other
5
+ end
6
+ end
7
+ end
@@ -51,5 +51,9 @@ module Stages
51
51
  def splice(*args, &block)
52
52
  Splice.new(*args, &block)
53
53
  end
54
+
55
+ def noop(*args, &block)
56
+ Noop.new(*args, &block)
57
+ end
54
58
  end
55
59
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "stages"
8
- s.version = "1.1.5"
8
+ s.version = "1.2.0"
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-08-30"
12
+ s.date = "2014-02-04"
13
13
  s.description = "pipeline builder"
14
14
  s.email = "support@igodigital.com"
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "examples/sing_subpipes.rb",
28
28
  "lib/stage_base.rb",
29
29
  "lib/stages.rb",
30
+ "lib/stages/Noop.rb",
30
31
  "lib/stages/cache.rb",
31
32
  "lib/stages/count.rb",
32
33
  "lib/stages/each.rb",
@@ -49,11 +50,11 @@ Gem::Specification.new do |s|
49
50
  ]
50
51
  s.homepage = "https://github.com/iGoDigital-LLC/stages"
51
52
  s.require_paths = ["lib"]
52
- s.rubygems_version = "2.0.7"
53
+ s.rubygems_version = "1.8.25"
53
54
  s.summary = "pipeline builder"
54
55
 
55
56
  if s.respond_to? :specification_version then
56
- s.specification_version = 4
57
+ s.specification_version = 3
57
58
 
58
59
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
60
  s.add_runtime_dependency(%q<rake>, [">= 0.9.2"])
@@ -87,4 +87,12 @@ class TestPipeline < MiniTest::Unit::TestCase
87
87
  assert_equal([2, 4], thing)
88
88
  end
89
89
  end
90
+
91
+ test "run_all runs the entire pipeline" do
92
+ side_effects = Hash.new(0)
93
+ pipeline = Each.new([:a, :b, :c, :b]) | Unique.new | Map.new{ |symbol| side_effects[symbol] += 1 }
94
+
95
+ assert_equal 3, pipeline.run_all
96
+ assert_equal({ :a => 1, :b => 1, :c => 1}, side_effects)
97
+ end
90
98
  end
@@ -190,6 +190,16 @@ class TestStages < MiniTest::Unit::TestCase
190
190
  assert_equal([1,2,3,4,4,5], pipeline.to_a)
191
191
  end
192
192
 
193
+ test "no-op stage is a no-op" do
194
+ pipeline = Noop.new | Select.new{ |x| true}
195
+ assert_equal :stages_eos, pipeline.run
196
+ end
197
+
198
+ test "no-op stage is a passthrough no-op" do
199
+ pipeline = Each.new([1, 2, 3]) | Noop.new | Select.new{ |x| true}
200
+ assert_equal([1, 2, 3], pipeline.to_a)
201
+ end
202
+
193
203
  test "splice with left hand input" do
194
204
  pipeline = Each.new([4,5]) | Splice.new(Each.new([1,2]), Each.new([3,4]))
195
205
  assert_equal([1,2,3,4,4,5], pipeline.to_a)
@@ -62,4 +62,9 @@ class TestSyntax < MiniTest::Unit::TestCase
62
62
  pipeline = splice(each([1,2]), each([3,4]), each([4,5]))
63
63
  assert_equal([1,2,3,4,4,5], pipeline.to_a)
64
64
  end
65
+
66
+ test "no-op stage is a no-op" do
67
+ pipeline = noop | Select.new{ |x| true}
68
+ assert_equal :stages_eos, pipeline.run
69
+ end
65
70
  end
metadata CHANGED
@@ -1,35 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: stages
3
- version: !ruby/object:Gem::Version
4
- version: 1.1.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Nathan D Acuff
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2013-08-30 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+ date: 2014-02-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &id001 !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
20
21
  version: 0.9.2
21
22
  type: :runtime
22
23
  prerelease: false
23
- version_requirements: *id001
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.2
24
30
  description: pipeline builder
25
31
  email: support@igodigital.com
26
32
  executables: []
27
-
28
33
  extensions: []
29
-
30
- extra_rdoc_files:
34
+ extra_rdoc_files:
31
35
  - README.md
32
- files:
36
+ files:
33
37
  - .autotest
34
38
  - .travis.yml
35
39
  - Gemfile
@@ -41,6 +45,7 @@ files:
41
45
  - examples/sing_subpipes.rb
42
46
  - lib/stage_base.rb
43
47
  - lib/stages.rb
48
+ - lib/stages/Noop.rb
44
49
  - lib/stages/cache.rb
45
50
  - lib/stages/count.rb
46
51
  - lib/stages/each.rb
@@ -62,29 +67,26 @@ files:
62
67
  - test/test_syntax.rb
63
68
  homepage: https://github.com/iGoDigital-LLC/stages
64
69
  licenses: []
65
-
66
- metadata: {}
67
-
68
70
  post_install_message:
69
71
  rdoc_options: []
70
-
71
- require_paths:
72
+ require_paths:
72
73
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
74
- requirements:
75
- - &id002
76
- - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
80
- requirements:
81
- - *id002
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
82
86
  requirements: []
83
-
84
87
  rubyforge_project:
85
- rubygems_version: 2.0.7
88
+ rubygems_version: 1.8.25
86
89
  signing_key:
87
- specification_version: 4
90
+ specification_version: 3
88
91
  summary: pipeline builder
89
92
  test_files: []
90
-
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: a2681dead96d1b78d4f1aee16f918316b824693a
4
- data.tar.gz: faf2b44e97a5f5dccc93f8275f51c95a1886b2bf
5
- SHA512:
6
- metadata.gz: 6c9f75f9c2aba60af3003222143c6378e93dc260e5bac9391c2161461c8f50045e734a25e6af8826f75b1947e399295f07e1702d21dfb2dacbac66aec5ebb5e5
7
- data.tar.gz: 3f6f6045ace7febe39688ed75b2efd9e9628b7e3025c8e568f47ddd2483a6281ea04b7ef3f5e20e26a7da658dc3f5e162e0b67b7a00822be114b560354f4ed6c