]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/registry/tc.rb
fix: TCPSocked.gethostbyname is deprecated
[user/henk/code/ruby/rbot.git] / lib / rbot / registry / tc.rb
1 #-- vim:sw=2:et
2 #++
3 #
4 # :title: TokyoCabinet B+Tree registry implementation
5 #
6 # TokyoCabinet is a "modern implementation of the DBM".
7 # http://fallabs.com/tokyocabinet/
8 #
9
10 require 'tokyocabinet'
11
12 module Irc
13 class Bot
14 class Registry
15
16   class TokyoCabinetAccessor < AbstractAccessor
17
18     def initialize(filename)
19       super filename + '.tdb'
20     end
21
22     def registry
23       super
24       unless @registry
25         @registry = TokyoCabinet::BDB.new
26         @registry.open(@filename, 
27           TokyoCabinet::BDB::OREADER | 
28           TokyoCabinet::BDB::OCREAT | 
29           TokyoCabinet::BDB::OWRITER)
30       end
31       @registry
32     end
33
34     def flush
35       return unless @registry
36       @registry.sync
37     end
38
39     def optimize
40       return unless @registry
41       @registry.optimize
42     end
43
44     def delete(key)
45       return default unless dbexists?
46       value = self[key]
47       registry.delete(key.to_s)
48       value # return deleted value if success
49     end
50
51   end
52
53 end # Registry
54 end # Bot
55 end # Irc
56