rufus-tokyo 0.1.1 → 0.1.2
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.
- data/CHANGELOG.txt +5 -0
- data/lib/rufus/tokyo.rb +21 -7
- data/test/cabinet_0_test.rb +20 -9
- metadata +1 -1
data/CHANGELOG.txt
CHANGED
data/lib/rufus/tokyo.rb
CHANGED
@@ -34,7 +34,7 @@ require 'ffi'
|
|
34
34
|
module Rufus
|
35
35
|
module Tokyo
|
36
36
|
|
37
|
-
VERSION = '0.1.
|
37
|
+
VERSION = '0.1.2'
|
38
38
|
|
39
39
|
module Func #:nodoc#
|
40
40
|
extend FFI::Library
|
@@ -240,15 +240,29 @@ module Tokyo
|
|
240
240
|
end
|
241
241
|
|
242
242
|
#
|
243
|
-
#
|
243
|
+
# Returns an array with all the keys in the databse
|
244
244
|
#
|
245
|
-
def
|
246
|
-
|
247
|
-
Rufus::Tokyo::Func.tcadbiterinit(@db)
|
248
|
-
|
245
|
+
def keys
|
246
|
+
a = []
|
247
|
+
Rufus::Tokyo::Func.tcadbiterinit(@db)
|
249
248
|
while (k = (Rufus::Tokyo::Func.tcadbiternext2(@db) rescue nil))
|
250
|
-
|
249
|
+
a << k
|
251
250
|
end
|
251
|
+
a
|
252
|
+
end
|
253
|
+
|
254
|
+
#
|
255
|
+
# Returns an array with all the values in the database (heavy...)
|
256
|
+
#
|
257
|
+
def values
|
258
|
+
collect { |k, v| v }
|
259
|
+
end
|
260
|
+
|
261
|
+
#
|
262
|
+
# The classical Ruby each (unlocks the power of the Enumerable mixin)
|
263
|
+
#
|
264
|
+
def each
|
265
|
+
keys.each { |k| yield(k, self[k]) }
|
252
266
|
end
|
253
267
|
end
|
254
268
|
end
|
data/test/cabinet_0_test.rb
CHANGED
@@ -14,10 +14,16 @@ require 'rufus/tokyo'
|
|
14
14
|
|
15
15
|
class CabinetZero < Test::Unit::TestCase
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def setup
|
18
|
+
@db = Rufus::Tokyo::Cabinet.new('test_data.tch')
|
19
|
+
@db.clear
|
20
|
+
end
|
21
|
+
def teardown
|
22
|
+
@db.close
|
23
|
+
end
|
24
|
+
def db
|
25
|
+
@db
|
26
|
+
end
|
21
27
|
|
22
28
|
def test_lib
|
23
29
|
|
@@ -26,7 +32,6 @@ class CabinetZero < Test::Unit::TestCase
|
|
26
32
|
|
27
33
|
def test_basic_workflow
|
28
34
|
|
29
|
-
db = Rufus::Tokyo::Cabinet.new('test_data.tch')
|
30
35
|
db['pillow'] = 'Shonagon'
|
31
36
|
|
32
37
|
assert_equal 1, db.size
|
@@ -34,22 +39,28 @@ class CabinetZero < Test::Unit::TestCase
|
|
34
39
|
|
35
40
|
assert_equal 'Shonagon', db.delete('pillow')
|
36
41
|
assert_equal 0, db.size
|
37
|
-
|
38
|
-
assert db.close
|
39
42
|
end
|
40
43
|
|
41
44
|
def test_clear
|
42
45
|
|
43
46
|
db = Rufus::Tokyo::Cabinet.new('test_data.tch')
|
47
|
+
db.clear
|
44
48
|
|
45
49
|
40.times { |i| db[i.to_s] = i.to_s }
|
46
50
|
assert_equal 40, db.size
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_keys_and_values
|
47
54
|
|
55
|
+
db = Rufus::Tokyo::Cabinet.new('test_data.tch')
|
48
56
|
db.clear
|
49
57
|
|
50
|
-
|
58
|
+
keys = %w{ alpha bravo charly delta echo foxtrott }
|
59
|
+
|
60
|
+
keys.each_with_index { |k, i| db[k] = i.to_s }
|
51
61
|
|
52
|
-
|
62
|
+
assert_equal keys, db.keys
|
63
|
+
assert_equal %w{ 0 1 2 3 4 5 }, db.values
|
53
64
|
end
|
54
65
|
|
55
66
|
end
|