leveldb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/leveldb/batch.rb +5 -0
- data/lib/leveldb/db.rb +25 -1
- data/lib/leveldb/iterator.rb +5 -0
- data/lib/leveldb/snapshot.rb +5 -0
- data/lib/leveldb/version.rb +1 -1
- data/test/test_db.rb +30 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45ece05a2078c65923a11be951e9bd4ed6065d52
|
4
|
+
data.tar.gz: 1e0067e76973f4562a84a8831cfb79e77289292a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d82cbd5f00b07320b1f02d01964b0f46c4dcf494e65dac1156e18aff8079c8ebddef747cabe1266111f3c5f88d2bd58c5142149a24cc2f07201e337688b54180
|
7
|
+
data.tar.gz: 00d47b0cf131dcf9edd6d2ddbf2fc4aaa64eab36179f0a5994fd0a3792067070b54e7fe79bfbdb06f3d9133f0e203c94b27320f269060ce978ef7bf9676eeabf
|
data/README.md
CHANGED
@@ -59,6 +59,11 @@ db['hello'] = 'world'
|
|
59
59
|
# Reading
|
60
60
|
db.get('hello') # => world
|
61
61
|
db['hello'] # => world
|
62
|
+
db.exists?('hello') # => true
|
63
|
+
|
64
|
+
# Reading/Writing
|
65
|
+
db.fetch('hello', 'hello world') # => will write 'hello world' if there is no key 'hello'
|
66
|
+
db.fetch('hello'){ |key| 'hello world' } # => same as above
|
62
67
|
|
63
68
|
# Deleting
|
64
69
|
db.delete('hello')
|
data/lib/leveldb/batch.rb
CHANGED
data/lib/leveldb/db.rb
CHANGED
@@ -8,6 +8,7 @@ module LevelDB
|
|
8
8
|
include Enumerable
|
9
9
|
|
10
10
|
class Error < StandardError; end
|
11
|
+
class KeyError < StandardError; end
|
11
12
|
class ClosedError < StandardError; end
|
12
13
|
|
13
14
|
attr_reader :path
|
@@ -85,7 +86,7 @@ module LevelDB
|
|
85
86
|
|
86
87
|
raise Error, error_message if errors?
|
87
88
|
|
88
|
-
|
89
|
+
@_read_len.value == 0 ? nil : val.to_s(@_read_len.value)
|
89
90
|
end
|
90
91
|
alias get []
|
91
92
|
|
@@ -101,6 +102,24 @@ module LevelDB
|
|
101
102
|
val
|
102
103
|
end
|
103
104
|
|
105
|
+
def exists?(key)
|
106
|
+
get(key) != nil
|
107
|
+
end
|
108
|
+
alias includes? exists?
|
109
|
+
alias contains? exists?
|
110
|
+
alias member? exists?
|
111
|
+
alias has_key? exists?
|
112
|
+
|
113
|
+
def fetch(key, default=nil, &block)
|
114
|
+
val = get(key)
|
115
|
+
|
116
|
+
return val if val
|
117
|
+
raise KeyError if default.nil? && !block_given?
|
118
|
+
|
119
|
+
val = block_given? ? block[key] : default
|
120
|
+
put(key, val)
|
121
|
+
end
|
122
|
+
|
104
123
|
def snapshot
|
105
124
|
Snapshot.new(@_db, @_read_opts)
|
106
125
|
end
|
@@ -195,5 +214,10 @@ module LevelDB
|
|
195
214
|
end
|
196
215
|
end
|
197
216
|
alias clear_errors! error_message
|
217
|
+
|
218
|
+
def inspect
|
219
|
+
"#<LevelDB::DB:#{'0x%x' % object_id}>"
|
220
|
+
end
|
221
|
+
alias to_s inspect
|
198
222
|
end
|
199
223
|
end
|
data/lib/leveldb/iterator.rb
CHANGED
data/lib/leveldb/snapshot.rb
CHANGED
data/lib/leveldb/version.rb
CHANGED
data/test/test_db.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require_relative './helper'
|
2
2
|
|
3
3
|
class TestBasic < Minitest::Test
|
4
|
+
attr_reader :db
|
4
5
|
|
5
|
-
def
|
6
|
-
|
6
|
+
def setup
|
7
|
+
@db ||= LevelDB::DB.new './tmp/test-db'
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
db.close
|
12
|
+
db.destroy
|
7
13
|
end
|
8
14
|
|
9
15
|
def test_open
|
@@ -29,6 +35,28 @@ class TestBasic < Minitest::Test
|
|
29
35
|
assert_equal 'bax', db[:foo]
|
30
36
|
end
|
31
37
|
|
38
|
+
def test_exists?
|
39
|
+
db[:foo] = :bar
|
40
|
+
|
41
|
+
assert db.exists?(:foo)
|
42
|
+
assert db.includes?(:foo)
|
43
|
+
assert db.contains?(:foo)
|
44
|
+
assert db.member?(:foo)
|
45
|
+
assert db.has_key?(:foo)
|
46
|
+
refute db.exists?(:foxy)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_fetch
|
50
|
+
db[:foo] = :bar
|
51
|
+
|
52
|
+
assert_equal 'bar', db.fetch(:foo)
|
53
|
+
assert_raises LevelDB::DB::KeyError do
|
54
|
+
db.fetch(:sten)
|
55
|
+
end
|
56
|
+
assert_equal 'smith', db.fetch(:sten, :smith)
|
57
|
+
assert_equal 'francine', db.fetch(:francine){ |key| key }
|
58
|
+
end
|
59
|
+
|
32
60
|
def test_delete
|
33
61
|
db[:foo] = 'bar'
|
34
62
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leveldb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DAddYE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fiddler-rb
|