obuf 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/README.md +2 -0
- data/lib/obuf.rb +1 -1
- data/lib/obuf/lens.rb +9 -2
- data/obuf.gemspec +1 -1
- data/test/test_obuf.rb +19 -2
- metadata +2 -2
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/lib/obuf.rb
CHANGED
@@ -19,7 +19,7 @@ require "thread" # required for ruby 18
|
|
19
19
|
#
|
20
20
|
# Both reading and writing aim to be threadsafe
|
21
21
|
class Obuf
|
22
|
-
VERSION = "1.2.
|
22
|
+
VERSION = "1.2.1"
|
23
23
|
require File.dirname(__FILE__) + "/obuf/lens"
|
24
24
|
require File.dirname(__FILE__) + "/obuf/protected_lens"
|
25
25
|
|
data/lib/obuf/lens.rb
CHANGED
@@ -3,6 +3,7 @@ require 'thread'
|
|
3
3
|
# Provides a per-object iterator on top of any IO object or pipe
|
4
4
|
class Obuf::Lens
|
5
5
|
include Enumerable
|
6
|
+
NothingToRecover = Class.new(StandardError)
|
6
7
|
|
7
8
|
DELIM = "\t"
|
8
9
|
END_RECORD = "\n"
|
@@ -32,7 +33,10 @@ class Obuf::Lens
|
|
32
33
|
skip_bytes = @io.gets("\t").to_i
|
33
34
|
@io.seek(@io.pos + skip_bytes + 1)
|
34
35
|
end
|
36
|
+
|
35
37
|
recover_object
|
38
|
+
rescue NothingToRecover # TODO: we need to honor this exception in the future
|
39
|
+
nil
|
36
40
|
end
|
37
41
|
|
38
42
|
# Recover the object at the current position in the IO. Returns +nil+
|
@@ -42,14 +46,17 @@ class Obuf::Lens
|
|
42
46
|
demarshal_bytes = @io.gets("\t").to_i
|
43
47
|
|
44
48
|
# When at end of IO return nil
|
45
|
-
|
49
|
+
raise NothingToRecover if demarshal_bytes.zero?
|
46
50
|
|
47
51
|
blob = @io.read(demarshal_bytes)
|
48
52
|
demarshal_object(blob)
|
49
53
|
end
|
50
54
|
|
51
55
|
def each
|
52
|
-
|
56
|
+
begin
|
57
|
+
loop { yield(recover_object) }
|
58
|
+
rescue NothingToRecover
|
59
|
+
end
|
53
60
|
end
|
54
61
|
|
55
62
|
private
|
data/obuf.gemspec
CHANGED
data/test/test_obuf.rb
CHANGED
@@ -132,8 +132,9 @@ class TestLens < Test::Unit::TestCase
|
|
132
132
|
lens = Obuf::Lens.new(mock_io)
|
133
133
|
lens << "Hi there!"
|
134
134
|
|
135
|
-
|
136
|
-
|
135
|
+
assert_raise Obuf::Lens::NothingToRecover do
|
136
|
+
lens.recover_object
|
137
|
+
end
|
137
138
|
|
138
139
|
mock_io.rewind
|
139
140
|
recovered = lens.recover_object
|
@@ -161,6 +162,22 @@ class TestLens < Test::Unit::TestCase
|
|
161
162
|
assert_equal [123, :a], items[2]
|
162
163
|
end
|
163
164
|
|
165
|
+
def test_lens_to_a
|
166
|
+
mock_io = StringIO.new
|
167
|
+
|
168
|
+
writing_lens = Obuf::Lens.new(mock_io)
|
169
|
+
writing_lens << "Hi there!"
|
170
|
+
writing_lens << 98121
|
171
|
+
writing_lens << [123, :a]
|
172
|
+
|
173
|
+
mock_io.rewind
|
174
|
+
|
175
|
+
reading_lens = Obuf::Lens.new(mock_io)
|
176
|
+
items = reading_lens.to_a
|
177
|
+
assert_equal 3, items.length
|
178
|
+
assert_equal "Hi there!", items[0]
|
179
|
+
end
|
180
|
+
|
164
181
|
def test_lens_recover_at
|
165
182
|
mock_io = StringIO.new
|
166
183
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
segments:
|
110
110
|
- 0
|
111
|
-
hash:
|
111
|
+
hash: 4000191137531519975
|
112
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|