streamingly 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/lib/streamingly/serde_iterable.rb +13 -2
- data/lib/streamingly/version.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/streamingly/reducer_spec.rb +28 -17
- data/spec/streamingly/serde_iterable_spec.rb +28 -0
- data/streamingly.gemspec +2 -2
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb1beb209148a563eaf9fc4f4d635607aceeebe3
|
4
|
+
data.tar.gz: 8631b810159e70ad32b5b2f34d5c811f1867cec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50b045493f03acd398b1ab93955472b93c07842b01e6446bd338250c224652b0d4a5d4a1f14e04c8d476ecb63a16954fc356742f82e16b55877f2ddbeb6e2988
|
7
|
+
data.tar.gz: 959f72ea4361803e7439dd7241b8f666f23bc39b0334c9d4f2b9cebf531b627b3bea2046b05773f4104127056535954c661c22b9638f27ca41b1b5c7573cfeaa
|
data/.travis.yml
ADDED
@@ -1,13 +1,24 @@
|
|
1
1
|
module Streamingly
|
2
2
|
|
3
3
|
class SerDeIterable
|
4
|
-
def initialize(iterable)
|
4
|
+
def initialize(iterable, error_handler = nil)
|
5
5
|
@iterable = iterable
|
6
|
+
@error_handler = error_handler
|
7
|
+
@error_callback_defined = @error_handler &&
|
8
|
+
@error_handler.respond_to?(:on_error)
|
6
9
|
end
|
7
10
|
|
8
11
|
def each
|
9
12
|
@iterable.each do |line|
|
10
|
-
|
13
|
+
begin
|
14
|
+
yield Streamingly::SerDe.from_tabbed_csv(line)
|
15
|
+
rescue => error
|
16
|
+
if @error_callback_defined
|
17
|
+
@error_handler.send(:on_error, error, line: line)
|
18
|
+
else
|
19
|
+
raise error
|
20
|
+
end
|
21
|
+
end
|
11
22
|
end
|
12
23
|
end
|
13
24
|
end
|
data/lib/streamingly/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,6 @@ require 'streamingly'
|
|
7
7
|
#
|
8
8
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
9
|
RSpec.configure do |config|
|
10
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
10
|
config.run_all_when_everything_filtered = true
|
12
11
|
config.filter_run :focus
|
13
12
|
|
@@ -58,12 +58,13 @@ describe Streamingly::Reducer do
|
|
58
58
|
let(:accumulator) { double(:accumulator, :flush => []) }
|
59
59
|
|
60
60
|
before do
|
61
|
-
accumulator_class
|
61
|
+
allow(accumulator_class).to \
|
62
|
+
receive(:new).with(key).and_return(accumulator)
|
62
63
|
end
|
63
64
|
|
64
65
|
it "combines them into the same accumulator" do
|
65
|
-
accumulator.
|
66
|
-
accumulator.
|
66
|
+
expect(accumulator).to receive(:apply_value).with(value1)
|
67
|
+
expect(accumulator).to receive(:apply_value).with(value2)
|
67
68
|
|
68
69
|
subject.reduce_over(records)
|
69
70
|
end
|
@@ -86,13 +87,15 @@ describe Streamingly::Reducer do
|
|
86
87
|
let(:accumulator2) { double(:accumulator, :flush => []) }
|
87
88
|
|
88
89
|
before do
|
89
|
-
accumulator_class
|
90
|
-
|
90
|
+
allow(accumulator_class).to \
|
91
|
+
receive(:new).with(key1).and_return(accumulator1)
|
92
|
+
allow(accumulator_class).to \
|
93
|
+
receive(:new).with(key2).and_return(accumulator2)
|
91
94
|
end
|
92
95
|
|
93
96
|
it "sends them to different accumulators" do
|
94
|
-
accumulator1.
|
95
|
-
accumulator2.
|
97
|
+
expect(accumulator1).to receive(:apply_value).with(value1)
|
98
|
+
expect(accumulator2).to receive(:apply_value).with(value2)
|
96
99
|
|
97
100
|
subject.reduce_over(records)
|
98
101
|
end
|
@@ -111,11 +114,12 @@ describe Streamingly::Reducer do
|
|
111
114
|
let(:accumulator) { double(:accumulator, :flush => []) }
|
112
115
|
|
113
116
|
before do
|
114
|
-
accumulator_class
|
117
|
+
allow(accumulator_class).to \
|
118
|
+
receive(:new).with(key).and_return(accumulator)
|
115
119
|
end
|
116
120
|
|
117
121
|
it "treats only the first tab as the key/value delimiter and leaves the value untouched" do
|
118
|
-
accumulator.
|
122
|
+
expect(accumulator).to receive(:apply_value).with(value)
|
119
123
|
|
120
124
|
subject.reduce_over(records)
|
121
125
|
end
|
@@ -136,7 +140,8 @@ describe Streamingly::Reducer do
|
|
136
140
|
|
137
141
|
context "with error callback specified" do
|
138
142
|
before do
|
139
|
-
accumulator_class
|
143
|
+
allow(accumulator_class).to \
|
144
|
+
receive(:new).with(key).and_return(accumulator)
|
140
145
|
end
|
141
146
|
|
142
147
|
it "keeps processing after error applying value" do
|
@@ -163,7 +168,8 @@ describe Streamingly::Reducer do
|
|
163
168
|
subject { described_class.new(accumulator_class) }
|
164
169
|
|
165
170
|
before do
|
166
|
-
|
171
|
+
allow(accumulator_class).to \
|
172
|
+
receive(:new).with(key).and_return(accumulator)
|
167
173
|
end
|
168
174
|
|
169
175
|
it "stops processing after error applying value" do
|
@@ -193,8 +199,10 @@ describe Streamingly::Reducer do
|
|
193
199
|
|
194
200
|
context "with error callback specified" do
|
195
201
|
before do
|
196
|
-
accumulator_class
|
197
|
-
|
202
|
+
allow(accumulator_class).to \
|
203
|
+
receive(:new).with(key1).and_return(accumulator1)
|
204
|
+
allow(accumulator_class).to \
|
205
|
+
receive(:new).with(key2).and_return(accumulator2)
|
198
206
|
end
|
199
207
|
|
200
208
|
it "keeps processing after error applying value" do
|
@@ -224,8 +232,10 @@ describe Streamingly::Reducer do
|
|
224
232
|
subject { described_class.new(accumulator_class) }
|
225
233
|
|
226
234
|
before do
|
227
|
-
accumulator_class
|
228
|
-
|
235
|
+
allow(accumulator_class).to \
|
236
|
+
receive(:new).with(key1).and_return(accumulator1)
|
237
|
+
allow(accumulator_class).to \
|
238
|
+
receive(:new).with(key2).and_return(accumulator2)
|
229
239
|
end
|
230
240
|
|
231
241
|
it "stops processing after error applying value" do
|
@@ -256,11 +266,12 @@ describe Streamingly::Reducer do
|
|
256
266
|
let(:accumulator) { double(:accumulator, :flush => []) }
|
257
267
|
|
258
268
|
before do
|
259
|
-
accumulator_class
|
269
|
+
allow(accumulator_class).to \
|
270
|
+
receive(:new).with(key, accumulator_options).and_return(accumulator)
|
260
271
|
end
|
261
272
|
|
262
273
|
it "uses the accumulator_options to initialize each accumulator" do
|
263
|
-
accumulator.
|
274
|
+
expect(accumulator).to receive(:apply_value).with(value)
|
264
275
|
|
265
276
|
subject.reduce_over(records)
|
266
277
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Streamingly::SerDeIterable do
|
4
|
+
let(:iterable) { [1] }
|
5
|
+
let(:error) { StandardError.new('error') }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(Streamingly::SerDe).to receive(:from_tabbed_csv).and_raise(error)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'no error handler given' do
|
12
|
+
subject { described_class.new(iterable) }
|
13
|
+
|
14
|
+
it 'raises error when calling each' do
|
15
|
+
expect { subject.each }.to raise_error(StandardError)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'given custom error handler' do
|
20
|
+
let(:error_handler) { double(:error_handler, respond_to?: true) }
|
21
|
+
subject { described_class.new(iterable, error_handler) }
|
22
|
+
|
23
|
+
it 'calls on_error method of provided handler' do
|
24
|
+
expect(error_handler).to receive(:on_error).with(error, line: 1)
|
25
|
+
expect { subject.each }.to_not raise_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/streamingly.gemspec
CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
22
|
spec.add_development_dependency "pry"
|
23
23
|
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "rspec", "~>
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.4.0"
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streamingly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Gillooly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.4.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 3.4.0
|
69
69
|
description: Helpful classes for writing streaming Hadoop jobs in Ruby
|
70
70
|
email:
|
71
71
|
- matt@swipely.com
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
77
|
- ".rspec"
|
78
|
+
- ".travis.yml"
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
@@ -87,6 +88,7 @@ files:
|
|
87
88
|
- lib/streamingly/version.rb
|
88
89
|
- spec/spec_helper.rb
|
89
90
|
- spec/streamingly/reducer_spec.rb
|
91
|
+
- spec/streamingly/serde_iterable_spec.rb
|
90
92
|
- spec/streamingly/serde_spec.rb
|
91
93
|
- streamingly.gemspec
|
92
94
|
homepage: http://github.com/swipely/streamingly
|
@@ -116,4 +118,5 @@ summary: Helpful classes for writing streaming Hadoop jobs in Ruby
|
|
116
118
|
test_files:
|
117
119
|
- spec/spec_helper.rb
|
118
120
|
- spec/streamingly/reducer_spec.rb
|
121
|
+
- spec/streamingly/serde_iterable_spec.rb
|
119
122
|
- spec/streamingly/serde_spec.rb
|