filter_io 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/filter_io.rb +5 -1
- data/test/filter_io_test.rb +21 -5
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/filter_io.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'active_support/core_ext/string'
|
3
|
+
require 'active_support/core_ext/array'
|
4
|
+
require 'active_support/core_ext/hash'
|
2
5
|
|
3
6
|
class FilterIO
|
4
7
|
|
@@ -269,7 +272,7 @@ class FilterIO
|
|
269
272
|
end
|
270
273
|
|
271
274
|
rescue NeedMoreData => e
|
272
|
-
raise EOFError, 'end of file reached' if eof?
|
275
|
+
raise EOFError, 'end of file reached' if @io.eof?
|
273
276
|
data << @io.read(block_size)
|
274
277
|
retry
|
275
278
|
end
|
@@ -304,6 +307,7 @@ class FilterIO
|
|
304
307
|
args = [data, state]
|
305
308
|
args = args.first(@block.arity > 0 ? @block.arity : 1)
|
306
309
|
data = @block.call(*args)
|
310
|
+
raise IOError, 'Block returned nil' if data.nil?
|
307
311
|
end
|
308
312
|
|
309
313
|
data
|
data/test/filter_io_test.rb
CHANGED
@@ -635,11 +635,20 @@ class FilterIOTest < ActiveSupport::TestCase
|
|
635
635
|
|
636
636
|
test "need more data at eof" do
|
637
637
|
input = "foo"
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
638
|
+
[2,3,6].each do |block_size|
|
639
|
+
[true, false].each do |always|
|
640
|
+
count = 0
|
641
|
+
io = FilterIO.new(StringIO.new(input), :block_size => block_size) do |data, state|
|
642
|
+
count += 1
|
643
|
+
raise FilterIO::NeedMoreData if state.eof? or always
|
644
|
+
data
|
645
|
+
end
|
646
|
+
assert_raise EOFError do
|
647
|
+
io.readline
|
648
|
+
end
|
649
|
+
expected_count = block_size < input.size ? 2 : 1
|
650
|
+
assert_equal expected_count, count
|
651
|
+
end
|
643
652
|
end
|
644
653
|
end
|
645
654
|
|
@@ -715,4 +724,11 @@ class FilterIOTest < ActiveSupport::TestCase
|
|
715
724
|
end
|
716
725
|
end
|
717
726
|
|
727
|
+
test "should raise IO error if block returns nil" do
|
728
|
+
io = FilterIO.new(StringIO.new("foo")) { |data| nil }
|
729
|
+
assert_raise IOError do
|
730
|
+
io.read.to_a
|
731
|
+
end
|
732
|
+
end
|
733
|
+
|
718
734
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filter_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Weathered
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-07-12 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|