obuf 1.2.0 → 1.2.1

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.
@@ -5,4 +5,3 @@ rvm:
5
5
  - 2.1.1
6
6
  - 2.2.0
7
7
  - jruby
8
- - ruby-head
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # obuf
2
2
 
3
+ [![Build Status](https://travis-ci.org/julik/obuf.svg?branch=master)](https://travis-ci.org/julik/obuf)
4
+
3
5
  A simple Ruby object buffer. Use this if you need to temporarily store alot of serializable Ruby objects.
4
6
 
5
7
  obuf = Obuf.new
@@ -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.0"
22
+ VERSION = "1.2.1"
23
23
  require File.dirname(__FILE__) + "/obuf/lens"
24
24
  require File.dirname(__FILE__) + "/obuf/protected_lens"
25
25
 
@@ -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
- return nil if demarshal_bytes == 0
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
- yield(recover_object) until @io.eof?
56
+ begin
57
+ loop { yield(recover_object) }
58
+ rescue NothingToRecover
59
+ end
53
60
  end
54
61
 
55
62
  private
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "obuf"
8
- s.version = "1.2.0"
8
+ s.version = "1.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Julik Tarkhanov"]
@@ -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
- recovered = lens.recover_object
136
- assert_nil recovered, "The IO is at the end now"
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.0
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: 4056659205467737583
111
+ hash: 4000191137531519975
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements: