streamingly 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
1
  module Streamingly
2
2
  class Reducer
3
3
 
4
- def initialize(accumulator_class)
4
+ def initialize(accumulator_class, accumulator_options=nil)
5
5
  @accumulator_class = accumulator_class
6
+ @accumulator_options = accumulator_options
6
7
  end
7
8
 
8
9
  def reduce_over(enumerator)
@@ -30,7 +31,7 @@ module Streamingly
30
31
  results = flush
31
32
 
32
33
  @prev_key = key
33
- @accumulator = @accumulator_class.new(key)
34
+ @accumulator = new_accumulator(key)
34
35
  end
35
36
 
36
37
  @accumulator.apply_value(value)
@@ -38,5 +39,12 @@ module Streamingly
38
39
  results || []
39
40
  end
40
41
 
42
+ def new_accumulator(key)
43
+ if @accumulator_options
44
+ @accumulator_class.new(key, @accumulator_options)
45
+ else
46
+ @accumulator_class.new(key)
47
+ end
48
+ end
41
49
  end
42
50
  end
@@ -1,3 +1,3 @@
1
1
  module Streamingly
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -62,6 +62,32 @@ describe Streamingly::Reducer do
62
62
  end
63
63
  end
64
64
 
65
+ context "when supplied with accumulator options" do
66
+ let(:accumulator_options) { { foo: 'bar' } }
67
+ subject { described_class.new(accumulator_class, accumulator_options) }
68
+
69
+ let(:key) { 'key' }
70
+ let(:value) { 'asdf' }
71
+
72
+ let(:records) {
73
+ [
74
+ [key, value].join("\t")
75
+ ]
76
+ }
77
+
78
+ let(:accumulator) { double(:accumulator, :flush => []) }
79
+
80
+ before do
81
+ accumulator_class.stub(:new).with(key, accumulator_options) { accumulator }
82
+ end
83
+
84
+ it "uses the accumulator_options to initialize each accumulator" do
85
+ accumulator.should_receive(:apply_value).with(value)
86
+
87
+ subject.reduce_over(records)
88
+ end
89
+ end
90
+
65
91
  end
66
92
 
67
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streamingly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-04 00:00:00.000000000 Z
12
+ date: 2013-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70096429996900 !ruby/object:Gem::Requirement
16
+ requirement: &70157983469340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70096429996900
24
+ version_requirements: *70157983469340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70096429996360 !ruby/object:Gem::Requirement
27
+ requirement: &70157983500960 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70096429996360
35
+ version_requirements: *70157983500960
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70096429995780 !ruby/object:Gem::Requirement
38
+ requirement: &70157983499200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70096429995780
46
+ version_requirements: *70157983499200
47
47
  description: Helpful classes for writing streaming Hadoop jobs in Ruby
48
48
  email:
49
49
  - matt@swipely.com
@@ -76,12 +76,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  - - ! '>='
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
+ segments:
80
+ - 0
81
+ hash: 1521604442353934601
79
82
  required_rubygems_version: !ruby/object:Gem::Requirement
80
83
  none: false
81
84
  requirements:
82
85
  - - ! '>='
83
86
  - !ruby/object:Gem::Version
84
87
  version: '0'
88
+ segments:
89
+ - 0
90
+ hash: 1521604442353934601
85
91
  requirements: []
86
92
  rubyforge_project:
87
93
  rubygems_version: 1.8.11
@@ -91,4 +97,3 @@ summary: Helpful classes for writing streaming Hadoop jobs in Ruby
91
97
  test_files:
92
98
  - spec/spec_helper.rb
93
99
  - spec/streamingly/reducer_spec.rb
94
- has_rdoc: