oj-pstore 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -3
- data/lib/oj/store.rb +5 -3
- metadata +11 -44
- data/.gitignore +0 -2
- data/gems.rb +0 -1
- data/oj-pstore.gemspec +0 -32
- data/rakefile.rb +0 -19
- data/test/oj_store_test.rb +0 -149
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4abfd6c5d996ef1381a92d01e6b53e2bdc5a2089ab23a2337271e4bc50aee493
|
4
|
+
data.tar.gz: 1359111aef09dcc79e8ac6db736257b1a333ef0a8bc29fe7a56d895d712347eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 423c94d01ecd47e12d0e7e9fca06328181b52b50f29ed5c381d6485a4bb11c322a3e3fa53734c06375ffe39f9ebf6c97cd423badc5cd1248005e764bf2d41780
|
7
|
+
data.tar.gz: b1a9acac1ad4f23cfef828ffde518559d10d3d090f63a6dc4af625ff1aa24f3eb9b47338b654da474c1c11a269aa51963d5d1157650f885777f5433e6f508629
|
data/README.md
CHANGED
@@ -2,11 +2,44 @@
|
|
2
2
|
|
3
3
|
This gem implements a [PStore](http://ruby-doc.org/stdlib-2.0/libdoc/pstore/rdoc/PStore.html) alternative using the fast [Oj](https://github.com/ohler55/oj#readme) gem.
|
4
4
|
|
5
|
-
|
5
|
+
- Gem: [rubygems.org](https://rubygems.org/gems/oj-pstore)
|
6
|
+
- Source: [github.com](https://github.com/mblumtritt/oj-pstore)
|
6
7
|
|
7
|
-
|
8
|
+
Use [Bundler](http://gembundler.com/) to add TCPClient in your own project:
|
8
9
|
|
10
|
+
Include in your `Gemfile`:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'oj-pstore'
|
14
|
+
```
|
15
|
+
|
16
|
+
and install it by running Bundler:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
To install the gem globally use:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
gem install oj-pstore
|
26
|
+
```
|
27
|
+
|
28
|
+
After that you need only a single line of code in your project to have it on board:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'oj/store'
|
32
|
+
```
|
9
33
|
## Documentation
|
10
34
|
|
11
|
-
The gem supports the [PStore](
|
35
|
+
The gem supports the [PStore](https://ruby-doc.org/stdlib-2.7.0/libdoc/pstore/rdoc/index.html) API.
|
36
|
+
|
37
|
+
## Sample
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# change a configuration value
|
41
|
+
require 'oj/store'
|
12
42
|
|
43
|
+
config = Oj::Store.new('config.json')
|
44
|
+
config.transaction{ config[:last_used] = Time.now }
|
45
|
+
```
|
data/lib/oj/store.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pstore'
|
2
4
|
require 'oj'
|
3
5
|
|
4
6
|
class Oj::Store < PStore
|
5
|
-
VERSION = '0.0.
|
7
|
+
VERSION = '0.0.5'
|
6
8
|
|
7
9
|
attr_reader :obtions
|
8
10
|
|
@@ -31,8 +33,8 @@ class Oj::Store < PStore
|
|
31
33
|
EMPTY_MARSHAL_CHECKSUM
|
32
34
|
end
|
33
35
|
|
34
|
-
private
|
35
|
-
|
36
36
|
EMPTY_MARSHAL_DATA = Oj.dump({}).freeze
|
37
37
|
EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA)
|
38
|
+
|
39
|
+
private_constant(:EMPTY_MARSHAL_DATA, :EMPTY_MARSHAL_CHECKSUM)
|
38
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj-pstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -24,53 +24,21 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
27
|
description: This gem implements a PStore alternative using the very fast Oj gem.
|
56
|
-
email:
|
28
|
+
email:
|
57
29
|
executables: []
|
58
30
|
extensions: []
|
59
31
|
extra_rdoc_files:
|
60
32
|
- README.md
|
61
33
|
files:
|
62
|
-
- ".gitignore"
|
63
34
|
- README.md
|
64
|
-
- gems.rb
|
65
35
|
- lib/oj/store.rb
|
66
|
-
- oj-pstore.gemspec
|
67
|
-
- rakefile.rb
|
68
|
-
- test/oj_store_test.rb
|
69
36
|
homepage: https://github.com/mblumtritt/oj-pstore
|
70
37
|
licenses: []
|
71
38
|
metadata:
|
72
|
-
|
73
|
-
|
39
|
+
source_code_uri: https://github.com/mblumtritt/oj-pstore
|
40
|
+
bug_tracker_uri: https://github.com/mblumtritt/oj-pstore/issues
|
41
|
+
post_install_message:
|
74
42
|
rdoc_options: []
|
75
43
|
require_paths:
|
76
44
|
- lib
|
@@ -83,11 +51,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
51
|
requirements:
|
84
52
|
- - ">="
|
85
53
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
54
|
+
version: '0'
|
87
55
|
requirements: []
|
88
|
-
rubygems_version: 3.
|
89
|
-
signing_key:
|
56
|
+
rubygems_version: 3.3.7
|
57
|
+
signing_key:
|
90
58
|
specification_version: 4
|
91
59
|
summary: PStore based on fast JSON parser/marshaller Oj.
|
92
|
-
test_files:
|
93
|
-
- test/oj_store_test.rb
|
60
|
+
test_files: []
|
data/.gitignore
DELETED
data/gems.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
source('https://rubygems.org'){ gemspec }
|
data/oj-pstore.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require_relative 'lib/oj/store'
|
2
|
-
|
3
|
-
GemSpec = Gem::Specification.new do |spec|
|
4
|
-
spec.name = 'oj-pstore'
|
5
|
-
spec.version = Oj::Store::VERSION
|
6
|
-
spec.summary = 'PStore based on fast JSON parser/marshaller Oj.'
|
7
|
-
spec.description =
|
8
|
-
'This gem implements a PStore alternative using the very fast Oj gem.'
|
9
|
-
spec.author = 'Mike Blumtritt'
|
10
|
-
spec.email = 'mike.blumtritt@invision.de'
|
11
|
-
spec.homepage = 'https://github.com/mblumtritt/oj-pstore'
|
12
|
-
spec.metadata = {
|
13
|
-
'issue_tracker' => 'https://github.com/mblumtritt/tcp-client/issues'
|
14
|
-
}
|
15
|
-
spec.rubyforge_project = spec.name
|
16
|
-
|
17
|
-
spec.add_dependency 'oj'
|
18
|
-
spec.add_development_dependency 'minitest'
|
19
|
-
spec.add_development_dependency 'rake'
|
20
|
-
|
21
|
-
spec.platform = Gem::Platform::RUBY
|
22
|
-
spec.required_ruby_version = '>= 2.0.0'
|
23
|
-
spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
|
24
|
-
|
25
|
-
spec.require_paths = %w[lib]
|
26
|
-
|
27
|
-
all_files = %x(git ls-files -z).split(0.chr)
|
28
|
-
spec.test_files = all_files.grep(%r{^(spec|test)/})
|
29
|
-
spec.files = all_files - spec.test_files
|
30
|
-
|
31
|
-
spec.extra_rdoc_files = %w[README.md]
|
32
|
-
end
|
data/rakefile.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rake/clean'
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'bundler/gem_tasks'
|
6
|
-
|
7
|
-
STDOUT.sync = STDERR.sync = true
|
8
|
-
|
9
|
-
CLOBBER << 'prj'
|
10
|
-
|
11
|
-
Rake::TestTask.new(:test) do |t|
|
12
|
-
t.ruby_opts = %w[-w]
|
13
|
-
t.verbose = true
|
14
|
-
t.test_files = FileList['test/**/*_test.rb']
|
15
|
-
end
|
16
|
-
|
17
|
-
task :default do
|
18
|
-
exec("#{$PROGRAM_NAME} --tasks")
|
19
|
-
end
|
data/test/oj_store_test.rb
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require_relative '../lib/oj/store'
|
3
|
-
|
4
|
-
class OjStoreTest < Minitest::Test
|
5
|
-
|
6
|
-
class SampleData
|
7
|
-
attr_accessor :name, :number
|
8
|
-
end
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@store_file = "oj-store.tmp.#{Process.pid}"
|
12
|
-
@store_file2 = "oj-store.2.tmp.#{Process.pid}"
|
13
|
-
@store = Oj::Store.new(@store_file)
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
File.file?(@store_file) and File.unlink(@store_file) rescue nil
|
18
|
-
File.file?(@store_file2) and File.unlink(@store_file2) rescue nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
|
22
|
-
@store.transaction(true) do
|
23
|
-
assert_nil @store[:foo]
|
24
|
-
assert_nil @store[:bar]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_opening_new_file_in_readwrite_mode_should_result_in_empty_values
|
29
|
-
@store.transaction do
|
30
|
-
assert_nil @store[:foo]
|
31
|
-
assert_nil @store[:bar]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_data_should_be_loaded_correctly_when_in_readonly_mode
|
36
|
-
@store.transaction do
|
37
|
-
@store[:foo] = 'bar'
|
38
|
-
end
|
39
|
-
@store.transaction(true) do
|
40
|
-
assert_equal 'bar', @store[:foo]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_data_should_be_loaded_correctly_when_in_readwrite_mode
|
45
|
-
@store.transaction do
|
46
|
-
@store[:foo] = 'bar'
|
47
|
-
end
|
48
|
-
@store.transaction do
|
49
|
-
assert_equal 'bar', @store[:foo]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_changes_after_commit_are_discarded
|
54
|
-
@store.transaction do
|
55
|
-
@store[:foo] = 'bar'
|
56
|
-
@store.commit
|
57
|
-
@store[:foo] = 'baz'
|
58
|
-
end
|
59
|
-
@store.transaction(true) do
|
60
|
-
assert_equal 'bar', @store[:foo]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_changes_are_not_written_on_abort
|
65
|
-
@store.transaction do
|
66
|
-
@store[:not_written] = 'just a value'
|
67
|
-
@store.abort
|
68
|
-
end
|
69
|
-
@store.transaction(true) do
|
70
|
-
assert_nil @store[:not_written]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_writing_inside_readonly_transaction_raises_error
|
75
|
-
assert_raises(PStore::Error) do
|
76
|
-
@store.transaction(true) do
|
77
|
-
@store[:foo] = 'bar'
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_thread_safe
|
83
|
-
assert_raises(PStore::Error) do
|
84
|
-
flag = false
|
85
|
-
Thread.new do
|
86
|
-
@store.transaction do
|
87
|
-
@store[:foo] = 'bar'
|
88
|
-
flag = true
|
89
|
-
sleep 1
|
90
|
-
end
|
91
|
-
end
|
92
|
-
until flag
|
93
|
-
# nop
|
94
|
-
end
|
95
|
-
@store.transaction {}
|
96
|
-
end
|
97
|
-
begin
|
98
|
-
pstore = PStore.new(@store_file2,true)
|
99
|
-
flag = false
|
100
|
-
Thread.new do
|
101
|
-
pstore.transaction do
|
102
|
-
pstore[:foo] = 'bar'
|
103
|
-
flag = true
|
104
|
-
sleep 1
|
105
|
-
end
|
106
|
-
end
|
107
|
-
until flag
|
108
|
-
# nop
|
109
|
-
end
|
110
|
-
pstore.transaction do
|
111
|
-
assert(pstore[:foo] == 'bar')
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_nested_transaction_raises_error
|
117
|
-
assert_raises(PStore::Error) do
|
118
|
-
@store.transaction { @store.transaction { } }
|
119
|
-
end
|
120
|
-
pstore = PStore.new(@store_file2, true)
|
121
|
-
assert_raises(PStore::Error) do
|
122
|
-
pstore.transaction { pstore.transaction { } }
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_extended_data
|
127
|
-
array= [1,2,3,4,'a','b','c']
|
128
|
-
hash= {a: 42, b: :c, d: 'e', 'f' => 4711}
|
129
|
-
s= SampleData.new
|
130
|
-
s.name = 'a name'
|
131
|
-
s.number = 12345678
|
132
|
-
@store.transaction do
|
133
|
-
@store[:string] = 'a simple string'
|
134
|
-
@store[:number] = 42.21
|
135
|
-
@store[:array] = array
|
136
|
-
@store[:hash] = hash
|
137
|
-
@store[:sample] = s
|
138
|
-
end
|
139
|
-
@store.transaction(true) do
|
140
|
-
assert_equal 'a simple string', @store[:string]
|
141
|
-
assert_equal 42.21, @store[:number]
|
142
|
-
assert_equal array, @store[:array]
|
143
|
-
assert_equal hash, @store[:hash]
|
144
|
-
assert_equal s.class, @store[:sample].class
|
145
|
-
assert_equal s.name, @store[:sample].name
|
146
|
-
assert_equal s.number, @store[:sample].number
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|