stages 0.4.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -35,6 +35,31 @@ pipeline = evens | map{|x| x*3} | select{|x| x % 7 == 0}
35
35
  ```
36
36
  Just include Stages::Sugar to get all the helpers.
37
37
 
38
+ Weird Stages
39
+ ------------
40
+
41
+ The feeder stage lets you have a pipeline which can add new values to the left hand side:
42
+ ```ruby
43
+ pipeline = feeder
44
+ feeder.done? # true
45
+ feeder << 1
46
+ feeder.done? # false
47
+ feeder.run # 1
48
+ feeder.done? # true
49
+ ```
50
+
51
+ The wrap stage has different behavior depending on the arguments you specify. In general, it runs the given pipeline in the context of the passed value. Wrap has various output modes you can use depending on what you are expecting.
52
+ ```ruby
53
+ emit('foo') | wrap(each{|x| x.chars}, :hash) # {'foo' => ['f', 'o', 'o']} this is the default
54
+ emit('foo') | wrap(each{|x| x.chars} | group, :aggregated) # {'foo' => {'f' => 1, 'o' => 2}} assumes a single value output
55
+ emit('foo') | wrap(each{|x| x.chars}, :array) # ['f', 'o', 'o'] discards the original value
56
+ emit('foo') | wrap(each{|x| x.chars}, :each) | run_until_exhausted # ['f', 'o', 'o'] equivalent to array + each
57
+ emit('foo') | wrap(each{|x| x.chars}){ |k, v| {k => v}} # {'foo' => ['f', 'o', 'o']
58
+ emit('foo') | wrap(each{|x| x.chars}, :each){|k, v| {k => v}} # {'foo' => 'f'} ... {'foo' => 'o'}
59
+ ```
60
+
61
+ Each does not build an internal list of results from the sub-array, and so may be useful in cases of high memory pressure when you are expecting many results for each input.
62
+
38
63
  Writing New Stages
39
64
  ------------------
40
65
 
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ Jeweler::Tasks.new do |gem|
25
25
  gem.summary = "pipeline builder"
26
26
  gem.description = "pipeline builder"
27
27
  gem.email = "support@igodigital.com"
28
- gem.authors = ["The Justice Eight"]
28
+ gem.authors = ["Nathan D Acuff"]
29
29
  # dependencies defined in Gemfile
30
30
  end
31
31
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 1.0.0
@@ -1,9 +1,13 @@
1
1
  module Stages
2
2
  class Wrap < Stage
3
- def initialize(pipeline, *args)
3
+
4
+ #pass a block that takes two arguments that joins the original thing passed to the results, for each result
5
+
6
+ def initialize(pipeline, *args, &block)
4
7
  @feeder = Feeder.new
5
8
  @pipeline = @feeder | pipeline
6
9
  @output_style = :hash
10
+ @block = block
7
11
  unless args.empty?
8
12
  if args.include? :array
9
13
  @output_style = :array
@@ -28,11 +32,27 @@ module Stages
28
32
  results = []
29
33
  while !@pipeline.done?
30
34
  v = @pipeline.run
31
- @output_style == :each ? output(v) : results << v
35
+ #yield each subpipeline result, as they are generated
36
+ if @output_style == :each
37
+ if @block
38
+ output @block.call(value, v)
39
+ else
40
+ output v
41
+ end
42
+ else
43
+ results << v
44
+ end
45
+ end
46
+ if @output_style != :each
47
+ results = results.first if @aggregated
48
+ #note that block supercedes array or hash
49
+ if @block
50
+ output @block.call(value, results)
51
+ else
52
+ output results if @output_style == :array
53
+ output({ value => results}) if @output_style == :hash
54
+ end
32
55
  end
33
- results = results.first if @aggregated
34
- output results if @output_style == :array
35
- output({ value => results}) if @output_style == :hash
36
56
  @pipeline.reset
37
57
  end
38
58
  @pipeline.reset
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "stages"
8
- s.version = "0.4.1"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["The Justice Eight"]
12
- s.date = "2012-04-16"
11
+ s.authors = ["Nathan D Acuff"]
12
+ s.date = "2012-07-13"
13
13
  s.description = "pipeline builder"
14
14
  s.email = "support@igodigital.com"
15
15
  s.extra_rdoc_files = [
@@ -46,7 +46,7 @@ Gem::Specification.new do |s|
46
46
  ]
47
47
  s.homepage = "https://github.com/iGoDigital-LLC/stages"
48
48
  s.require_paths = ["lib"]
49
- s.rubygems_version = "1.8.17"
49
+ s.rubygems_version = "1.8.19"
50
50
  s.summary = "pipeline builder"
51
51
 
52
52
  if s.respond_to? :specification_version then
@@ -48,6 +48,27 @@ class TestStages < MiniTest::Unit::TestCase
48
48
  assert_equal(3, result['bar'].keys.length)
49
49
  end
50
50
 
51
+ test 'wrap/join array' do
52
+ pipeline = Each.new(%w(foo bar)) | Wrap.new(Each.new{ |x| x.chars}) { |context, values| { context => values}}
53
+ result = pipeline.run
54
+ assert_equal({ 'foo' => %w(f o o)}, result)
55
+ end
56
+
57
+ test 'wrap/join each' do
58
+ pipeline = Each.new(%w(foo bar)) | Wrap.new(Each.new{ |x| x.chars}, :each) { |context, values| { context => values}}
59
+ result = pipeline.run
60
+ assert_equal({ 'foo' => 'f'}, result)
61
+ result = pipeline.run
62
+ assert_equal({ 'foo' => 'o'}, result)
63
+ result = pipeline.run
64
+ assert_equal({ 'foo' => 'o'}, result)
65
+ result = pipeline.run
66
+ assert_equal({ 'bar' => 'b'}, result)
67
+ result = pipeline.run
68
+ assert_equal({ 'bar' => 'a'}, result)
69
+ result = pipeline.run
70
+ assert_equal({ 'bar' => 'r'}, result)
71
+ end
51
72
 
52
73
  test 'array mode wrap' do
53
74
  pipeline = Each.new(%w(foo bar)) | Wrap.new(Each.new{ |x| x.chars}, :array)
metadata CHANGED
@@ -1,37 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: stages
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
4
5
  prerelease:
5
- version: 0.4.1
6
6
  platform: ruby
7
- authors:
8
- - The Justice Eight
7
+ authors:
8
+ - Nathan D Acuff
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-04-16 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-07-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rake
17
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  none: false
19
- requirements:
20
- - - "="
21
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
22
21
  version: 0.9.2
23
22
  type: :runtime
24
23
  prerelease: false
25
- 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
26
30
  description: pipeline builder
27
31
  email: support@igodigital.com
28
32
  executables: []
29
-
30
33
  extensions: []
31
-
32
- extra_rdoc_files:
34
+ extra_rdoc_files:
33
35
  - README.md
34
- files:
36
+ files:
35
37
  - .autotest
36
38
  - Gemfile
37
39
  - Gemfile.lock
@@ -61,33 +63,29 @@ files:
61
63
  - test/test_syntax.rb
62
64
  homepage: https://github.com/iGoDigital-LLC/stages
63
65
  licenses: []
64
-
65
66
  post_install_message:
66
67
  rdoc_options: []
67
-
68
- require_paths:
68
+ require_paths:
69
69
  - lib
70
- required_ruby_version: !ruby/object:Gem::Requirement
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
71
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3910381420948442962
76
- segments:
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
77
  - 0
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
78
+ hash: 667046773893445689
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: "0"
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
85
  requirements: []
86
-
87
86
  rubyforge_project:
88
- rubygems_version: 1.8.17
87
+ rubygems_version: 1.8.19
89
88
  signing_key:
90
89
  specification_version: 3
91
90
  summary: pipeline builder
92
91
  test_files: []
93
-