rufus-tokyo 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,11 @@
2
2
  = rufus-tokyo CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-tokyo - 0.1.2 released 2009/01/23
6
+
7
+ - todo : implemented Cabinet#keys and #values
8
+
9
+
5
10
  == rufus-tokyo - 0.1.1 released 2009/01/23
6
11
 
7
12
  - bug : fixed dependency, it's ffi not ruby-ffi
@@ -34,7 +34,7 @@ require 'ffi'
34
34
  module Rufus
35
35
  module Tokyo
36
36
 
37
- VERSION = '0.1.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
- # The classical Ruby each (unlocks the power of the Enumerable mixin)
243
+ # Returns an array with all the keys in the databse
244
244
  #
245
- def each
246
-
247
- Rufus::Tokyo::Func.tcadbiterinit(@db) # concurrent access ??
248
-
245
+ def keys
246
+ a = []
247
+ Rufus::Tokyo::Func.tcadbiterinit(@db)
249
248
  while (k = (Rufus::Tokyo::Func.tcadbiternext2(@db) rescue nil))
250
- yield(k, self[k])
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
@@ -14,10 +14,16 @@ require 'rufus/tokyo'
14
14
 
15
15
  class CabinetZero < Test::Unit::TestCase
16
16
 
17
- #def setup
18
- #end
19
- #def teardown
20
- #end
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
- assert_equal 0, db.size
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
- assert db.close
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-tokyo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux