]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/registry/dbm.rb
[registry] refactoring into a abstract and factory
[user/henk/code/ruby/rbot.git] / lib / rbot / registry / dbm.rb
1 #-- vim:sw=2:et
2 #++
3 #
4 # :title: DBM registry implementation
5 #
6 # DBM is the ruby standard library wrapper module for Unix-style
7 # dbm libraries. The specific library used depends
8 # on how ruby was compiled. Its any of the following: ndbm, bdb,
9 # gdbm or qdbm.
10 # http://ruby-doc.org/stdlib-2.1.0/libdoc/dbm/rdoc/DBM.html
11 #
12
13 require 'dbm'
14
15 module Irc
16 class Bot
17 class Registry
18
19   class DBMAccessor < AbstractAccessor
20
21     def registry
22       super
23       @registry ||= DBM.open(@filename, 0666, DBM::WRCREAT)
24     end
25
26     def flush
27       return if !@registry
28       # ruby dbm has no flush, so we close/reopen :(
29       close
30       registry
31     end
32
33     def dbexists?
34       not Dir.glob(@filename + '.*').empty?
35     end
36
37     def optimize
38       # unsupported!
39     end
40
41   end
42
43 end # Registry
44 end # Bot
45 end # Irc
46