perobs 1.1.0 → 2.0.0

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.
@@ -23,10 +23,7 @@
23
23
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
24
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
25
 
26
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
27
-
28
- require 'fileutils'
29
- require 'time'
26
+ require 'spec_helper'
30
27
  require 'perobs'
31
28
 
32
29
  class Person < PEROBS::Object
@@ -45,43 +42,43 @@ end
45
42
  describe PEROBS::Store do
46
43
 
47
44
  before(:all) do
48
- FileUtils.rm_rf('test_db')
45
+ @db_name = File.join(Dir.tmpdir, "perobs_spec.#{rand(2**32)}")
49
46
  end
50
47
 
51
48
  after(:each) do
52
- FileUtils.rm_rf('test_db')
49
+ FileUtils.rm_rf(@db_name)
53
50
  end
54
51
 
55
52
  it 'should store simple objects' do
56
- store = PEROBS::Store.new('test_db')
57
- store['john'] = john = Person.new(store)
53
+ store = PEROBS::Store.new(@db_name)
54
+ store['john'] = john = store.new(Person)
58
55
  john.name = 'John'
59
56
  john.zip = 4060
60
57
  john.bmi = 25.5
61
- store['jane'] = jane = Person.new(store)
58
+ store['jane'] = jane = store.new(Person)
62
59
  jane.name = 'Jane'
63
60
  jane.related = john
64
61
  jane.married = true
65
62
  jane.relatives = 'test'
66
63
 
67
- john.name.should == 'John'
68
- john.zip.should == 4060
69
- john.bmi.should == 25.5
70
- john.married.should be_false
71
- john.related.should be_nil
64
+ expect(john.name).to eq('John')
65
+ expect(john.zip).to eq(4060)
66
+ expect(john.bmi).to eq(25.5)
67
+ expect(john.married).to be false
68
+ expect(john.related).to be_nil
72
69
  jane = store['jane']
73
- jane.name.should == 'Jane'
74
- jane.related.should == john
75
- jane.married.should be_true
70
+ expect(jane.name).to eq('Jane')
71
+ expect(jane.related).to eq(john)
72
+ expect(jane.married).to be true
76
73
  end
77
74
 
78
75
  it 'should store and retrieve simple objects' do
79
- store = PEROBS::Store.new('test_db')
80
- store['john'] = john = Person.new(store)
76
+ store = PEROBS::Store.new(@db_name)
77
+ store['john'] = john = store.new(Person)
81
78
  john.name = 'John'
82
79
  john.zip = 4060
83
80
  john.bmi = 25.5
84
- store['jane'] = jane = Person.new(store)
81
+ store['jane'] = jane = store.new(Person)
85
82
  jane.name = 'Jane'
86
83
  jane.related = john
87
84
  jane.married = true
@@ -89,67 +86,67 @@ describe PEROBS::Store do
89
86
 
90
87
  store.sync
91
88
 
92
- store = PEROBS::Store.new('test_db')
89
+ store = PEROBS::Store.new(@db_name)
93
90
  john = store['john']
94
- john.name.should == 'John'
95
- john.zip.should == 4060
96
- john.bmi.should == 25.5
97
- john.married.should be_false
98
- john.related.should be_nil
91
+ expect(john.name).to eq('John')
92
+ expect(john.zip).to eq(4060)
93
+ expect(john.bmi).to eq(25.5)
94
+ expect(john.married).to be false
95
+ expect(john.related).to be_nil
99
96
  jane = store['jane']
100
- jane.name.should == 'Jane'
101
- jane.related.should == john
102
- jane.married.should be_true
97
+ expect(jane.name).to eq('Jane')
98
+ expect(jane.related).to eq(john)
99
+ expect(jane.married).to be true
103
100
  end
104
101
 
105
102
  it 'should flush cached objects when necessary' do
106
- store = PEROBS::Store.new('test_db', :cache_bits => 3)
103
+ store = PEROBS::Store.new(@db_name, :cache_bits => 3)
107
104
  last_obj = nil
108
105
  0.upto(20) do |i|
109
- store["person#{i}"] = obj = Person.new(store)
110
- store["person#{i}"].should == obj
106
+ store["person#{i}"] = obj = store.new(Person)
107
+ expect(store["person#{i}"]).to eq(obj)
111
108
  obj.name = "Person #{i}"
112
- obj.name.should == "Person #{i}"
109
+ expect(obj.name).to eq("Person #{i}")
113
110
  obj.related = last_obj
114
- obj.related.should == last_obj
111
+ expect(obj.related).to eq(last_obj)
115
112
  last_obj = obj
116
113
  end
117
114
  0.upto(20) do |i|
118
- store["person#{i}"].name.should == "Person #{i}"
115
+ expect(store["person#{i}"].name).to eq("Person #{i}")
119
116
  end
120
117
  end
121
118
 
122
119
  it 'should detect modification to non-working objects' do
123
- store = PEROBS::Store.new('test_db', :cache_bits => 3)
120
+ store = PEROBS::Store.new(@db_name, :cache_bits => 3)
124
121
  0.upto(20) do |i|
125
- store["person#{i}"] = obj = Person.new(store)
122
+ store["person#{i}"] = obj = store.new(Person)
126
123
  obj.name = "Person #{i}"
127
124
  end
128
125
  0.upto(20) do |i|
129
126
  store["person#{i}"].name = "New Person #{i}"
130
127
  end
131
128
  store.sync
132
- store = PEROBS::Store.new('test_db')
129
+ store = PEROBS::Store.new(@db_name)
133
130
  0.upto(20) do |i|
134
- store["person#{i}"].name.should == "New Person #{i}"
131
+ expect(store["person#{i}"].name).to eq("New Person #{i}")
135
132
  end
136
133
  end
137
134
 
138
135
  it 'should garbage collect unlinked objects' do
139
- store = PEROBS::Store.new('test_db')
140
- store['person1'] = obj = Person.new(store)
136
+ store = PEROBS::Store.new(@db_name)
137
+ store['person1'] = obj = store.new(Person)
141
138
  id1 = obj._id
142
- store['person2'] = obj = Person.new(store)
139
+ store['person2'] = obj = store.new(Person)
143
140
  id2 = obj._id
144
- obj.related = obj = Person.new(store)
141
+ obj.related = obj = store.new(Person)
145
142
  id3 = obj._id
146
143
  store.sync
147
144
  store['person1'] = nil
148
145
  store.gc
149
- store = PEROBS::Store.new('test_db')
150
- store.object_by_id(id1).should be_nil
151
- store['person2']._id.should == id2
152
- store['person2'].related._id.should == id3
146
+ store = PEROBS::Store.new(@db_name)
147
+ expect(store.object_by_id(id1)).to be_nil
148
+ expect(store['person2']._id).to eq(id2)
149
+ expect(store['person2'].related._id).to eq(id3)
153
150
  end
154
151
 
155
152
  end
@@ -25,70 +25,18 @@
25
25
 
26
26
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
27
27
 
28
+ require 'tmpdir'
28
29
  require 'fileutils'
29
- require 'time'
30
-
31
- require 'perobs'
32
-
33
- class PO < PEROBS::Object
34
-
35
- po_attr :name
36
-
37
- def initialize(store, name = nil)
38
- super(store)
39
- set(:name, name)
40
- end
41
30
 
31
+ class UStruct < Struct.new(:first, :second, :third)
42
32
  end
43
33
 
44
- describe PEROBS::Array do
45
-
46
- before(:all) do
47
- @db_name = 'test_db'
48
- FileUtils.rm_rf(@db_name)
49
- end
50
-
51
- after(:each) do
52
- FileUtils.rm_rf(@db_name)
53
- end
54
-
55
- it 'should store simple objects persistently' do
56
- store = PEROBS::Store.new(@db_name)
57
- store['a'] = a = PEROBS::Array.new(store)
58
- a[0] = 'A'
59
- a[1] = 'B'
60
- a[2] = po = PO.new(store)
61
- po.name = 'foobar'
62
-
63
- a[0].should == 'A'
64
- a[1].should == 'B'
65
- a[2].name.should == 'foobar'
66
- store.sync
67
-
68
- store = PEROBS::Store.new(@db_name)
69
- a = store['a']
70
- a[0].should == 'A'
71
- a[1].should == 'B'
72
- a[2].name.should == 'foobar'
73
- end
74
-
75
- it 'should have an each method to iterate' do
76
- store = PEROBS::Store.new(@db_name)
77
- store['a'] = a = PEROBS::Array.new(store)
78
- a[0] = 'A'
79
- a[1] = 'B'
80
- a[2] = 'C'
81
- vs = ''
82
- a.each { |v| vs << v }
83
- vs.should == 'ABC'
84
- store.sync
85
-
86
- store = PEROBS::Store.new(@db_name)
87
- a = store['a']
88
- vs = ''
89
- a[3] = PO.new(store, 'D')
90
- a.each { |v| vs << (v.is_a?(String) ? v : v.name) }
91
- vs.should == 'ABCD'
92
- end
34
+ def generate_db_name(caller_file)
35
+ begin
36
+ db_name = File.join(Dir.tmpdir,
37
+ "#{File.basename(caller_file)}.#{rand(2**32)}")
38
+ end while File.exists?(db_name)
93
39
 
40
+ db_name
94
41
  end
42
+
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schlaeger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-26 00:00:00.000000000 Z
11
+ date: 2015-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
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
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: yard
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.8.7
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.8.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  description: Library to provide a persistent object store
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -71,6 +71,7 @@ files:
71
71
  - lib/perobs/Cache.rb
72
72
  - lib/perobs/ClassMap.rb
73
73
  - lib/perobs/DataBase.rb
74
+ - lib/perobs/Delegator.rb
74
75
  - lib/perobs/DynamoDB.rb
75
76
  - lib/perobs/Hash.rb
76
77
  - lib/perobs/Object.rb
@@ -78,17 +79,18 @@ files:
78
79
  - lib/perobs/Store.rb
79
80
  - lib/perobs/version.rb
80
81
  - perobs.gemspec
81
- - spec/Array_spec.rb
82
- - spec/BTreeDB_spec.rb
83
- - spec/ClassMap_spec.rb
84
- - spec/Hash_spec.rb
85
- - spec/Object_spec.rb
86
- - spec/Store_spec.rb
87
- - spec/perobs_spec.rb
88
82
  - tasks/changelog.rake
89
83
  - tasks/gem.rake
90
84
  - tasks/rdoc.rake
91
85
  - tasks/test.rake
86
+ - test/Array_spec.rb
87
+ - test/BTreeDB_spec.rb
88
+ - test/ClassMap_spec.rb
89
+ - test/Hash_spec.rb
90
+ - test/Object_spec.rb
91
+ - test/Store_spec.rb
92
+ - test/perobs_spec.rb
93
+ - test/spec_helper.rb
92
94
  homepage: https://github.com/scrapper/perobs
93
95
  licenses:
94
96
  - MIT
@@ -99,26 +101,27 @@ require_paths:
99
101
  - lib
100
102
  required_ruby_version: !ruby/object:Gem::Requirement
101
103
  requirements:
102
- - - '>='
104
+ - - ">="
103
105
  - !ruby/object:Gem::Version
104
106
  version: '2.0'
105
107
  required_rubygems_version: !ruby/object:Gem::Requirement
106
108
  requirements:
107
- - - '>='
109
+ - - ">="
108
110
  - !ruby/object:Gem::Version
109
111
  version: '0'
110
112
  requirements: []
111
113
  rubyforge_project:
112
- rubygems_version: 2.0.3
114
+ rubygems_version: 2.4.5.1
113
115
  signing_key:
114
116
  specification_version: 4
115
117
  summary: Persistent Ruby Object Store
116
118
  test_files:
117
- - spec/Array_spec.rb
118
- - spec/BTreeDB_spec.rb
119
- - spec/ClassMap_spec.rb
120
- - spec/Hash_spec.rb
121
- - spec/Object_spec.rb
122
- - spec/Store_spec.rb
123
- - spec/perobs_spec.rb
119
+ - test/Array_spec.rb
120
+ - test/BTreeDB_spec.rb
121
+ - test/ClassMap_spec.rb
122
+ - test/Hash_spec.rb
123
+ - test/Object_spec.rb
124
+ - test/Store_spec.rb
125
+ - test/perobs_spec.rb
126
+ - test/spec_helper.rb
124
127
  has_rdoc:
data/spec/Hash_spec.rb DELETED
@@ -1,96 +0,0 @@
1
- # encoding: UTF-8
2
- #
3
- # Copyright (c) 2015 by Chris Schlaeger <chris@taskjuggler.org>
4
- #
5
- # MIT License
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining
8
- # a copy of this software and associated documentation files (the
9
- # "Software"), to deal in the Software without restriction, including
10
- # without limitation the rights to use, copy, modify, merge, publish,
11
- # distribute, sublicense, and/or sell copies of the Software, and to
12
- # permit persons to whom the Software is furnished to do so, subject to
13
- # the following conditions:
14
- #
15
- # The above copyright notice and this permission notice shall be
16
- # included in all copies or substantial portions of the Software.
17
- #
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
-
26
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
27
-
28
- require 'fileutils'
29
- require 'time'
30
-
31
- require 'perobs'
32
-
33
-
34
- class PO < PEROBS::Object
35
-
36
- po_attr :name
37
-
38
- def initialize(store, name = nil)
39
- super(store)
40
- @name = name
41
- end
42
-
43
- end
44
-
45
- describe PEROBS::Hash do
46
-
47
- before(:all) do
48
- @db_name = 'test_db'
49
- FileUtils.rm_rf(@db_name)
50
- end
51
-
52
- after(:each) do
53
- FileUtils.rm_rf(@db_name)
54
- end
55
-
56
- it 'should store simple objects persistently' do
57
- store = PEROBS::Store.new(@db_name)
58
- store['h'] = h = PEROBS::Hash.new(store)
59
- h['a'] = 'A'
60
- h['b'] = 'B'
61
- h['po'] = po = PO.new(store)
62
- po.name = 'foobar'
63
- h['b'] = 'B'
64
-
65
- h['a'].should == 'A'
66
- h['b'].should == 'B'
67
- store.sync
68
-
69
- store = PEROBS::Store.new(@db_name)
70
- h = store['h']
71
- h['a'].should == 'A'
72
- h['b'].should == 'B'
73
- h['po'].name.should == 'foobar'
74
- end
75
-
76
- it 'should have an each method to iterate' do
77
- store = PEROBS::Store.new(@db_name)
78
- store['h'] = h = PEROBS::Hash.new(store)
79
- h['a'] = 'A'
80
- h['b'] = 'B'
81
- h['c'] = 'C'
82
- vs = []
83
- h.each { |k, v| vs << k + v }
84
- vs.sort.join.should == 'aAbBcC'
85
-
86
- store = PEROBS::Store.new(@db_name)
87
- store['h'] = h = PEROBS::Hash.new(store)
88
- h['a'] = PO.new(store, 'A')
89
- h['b'] = PO.new(store, 'B')
90
- h['c'] = PO.new(store, 'C')
91
- vs = []
92
- h.each { |k, v| vs << k + v.name }
93
- vs.sort.join.should == 'aAbBcC'
94
- end
95
-
96
- end