obuf 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 1.1.0 / 2011-08-02
2
+
3
+ * Stores every item from the Enumerable passed to the constructor
4
+ * Supports block initialization
5
+
1
6
  === 1.0.3 / 2011-08-02
2
7
 
3
8
  * Fix the gem packaging issue
@@ -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.0.4"
22
+ VERSION = "1.1.0"
23
23
 
24
24
  include Enumerable
25
25
 
@@ -29,14 +29,19 @@ class Obuf
29
29
  # Returns the number of objects stored so far
30
30
  attr_reader :size
31
31
 
32
- def initialize
32
+ # Initializes a new Obuf. If an Enumerable argument is passed each element from the
33
+ # Enumerable will be stored in the Obuf (so you can pass an IO for example)
34
+ def initialize(enumerable = [])
33
35
  @sem = Mutex.new
34
36
  @store = Tempfile.new("obuf")
35
37
  @store.set_encoding(Encoding::BINARY) if @store.respond_to?(:set_encoding)
36
38
  @store.binmode
37
-
38
39
  @size = 0
39
- super
40
+
41
+ # Store everything from the enumerable in self
42
+ enumerable.each(&method(:push))
43
+
44
+ yield self if block_given?
40
45
  end
41
46
 
42
47
  # Tells whether the buffer is empty
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "obuf"
8
- s.version = "1.0.4"
8
+ s.version = "1.1.0"
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"]
12
- s.date = "2012-01-10"
12
+ s.date = "2012-02-27"
13
13
  s.description = "Stores marshaled temporary objects on-disk in a simple Enumerable"
14
14
  s.email = "me@julik.nl"
15
15
  s.extra_rdoc_files = [
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.homepage = "http://github.com/julik/obuf"
30
30
  s.licenses = ["MIT"]
31
31
  s.require_paths = ["lib"]
32
- s.rubygems_version = "1.8.11"
32
+ s.rubygems_version = "1.8.15"
33
33
  s.summary = "Ruby disk-backed object buffer"
34
34
 
35
35
  if s.respond_to? :specification_version then
@@ -24,6 +24,20 @@ class TestObuf < Test::Unit::TestCase
24
24
  assert_equal values, a.map{|e| e }, "Should return the same elements from the storage"
25
25
  end
26
26
 
27
+ def test_initialize_with_block
28
+ o = Obuf.new do | buf |
29
+ buf.push("Excitement!")
30
+ end
31
+
32
+ assert_equal 1, o.size
33
+ assert_equal %w( Excitement! ), o.to_a
34
+ end
35
+
36
+ def test_from_enum
37
+ a = Obuf.new([1,2,3])
38
+ assert_equal [1,2,3], a.to_a
39
+ end
40
+
27
41
  def test_accumulator_saves_shitload_of_objs
28
42
  a = Obuf.new
29
43
  50_000.times { a.push("A string" => rand) }
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.0.4
4
+ version: 1.1.0
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: 2012-01-10 00:00:00.000000000 Z
12
+ date: 2012-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jeweler
16
- requirement: &10064560 !ruby/object:Gem::Requirement
16
+ requirement: &4139570 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *10064560
24
+ version_requirements: *4139570
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &10064250 !ruby/object:Gem::Requirement
27
+ requirement: &4139080 !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: *10064250
35
+ version_requirements: *4139080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: flexmock
38
- requirement: &10063930 !ruby/object:Gem::Requirement
38
+ requirement: &4138610 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0.8'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *10063930
46
+ version_requirements: *4138610
47
47
  description: Stores marshaled temporary objects on-disk in a simple Enumerable
48
48
  email: me@julik.nl
49
49
  executables: []
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  requirements: []
83
83
  rubyforge_project:
84
- rubygems_version: 1.8.11
84
+ rubygems_version: 1.8.15
85
85
  signing_key:
86
86
  specification_version: 3
87
87
  summary: Ruby disk-backed object buffer