DBHash is for tying a hash to disk (using bdb). Call it with an identifier, for example "mydata". It'll look for mydata.db, if it exists, it will load and reference that db. Otherwise it'll create and empty db called mydata.db
DBHash is for tying a hash to disk (using bdb). Call it with an identifier, for example "mydata". It'll look for mydata.db, if it exists, it will load and reference that db. Otherwise it'll create and empty db called mydata.db
# File lib/rbot/registry/bdb.rb, line 76 def DBHash.create_db(name) debug "DBHash: creating empty db #{name}" return BDB::Hash.open(name, nil, BDB::CREATE | BDB::EXCL, 0600) end
use key
as an actual filename, don’t prepend the bot’s config
path and don’t append “.db”
# File lib/rbot/registry/bdb.rb, line 52 def initialize(bot, key, absfilename=false) @bot = bot @key = key relfilename = @bot.path key relfilename << '.db' if absfilename && File.exist?(key) # db already exists, use it @db = DBHash.open_db(key) elsif absfilename # create empty db @db = DBHash.create_db(key) elsif File.exist? relfilename # db already exists, use it @db = DBHash.open_db relfilename else # create empty db @db = DBHash.create_db relfilename end end
# File lib/rbot/registry/bdb.rb, line 82 def DBHash.open_db(name) debug "DBHash: opening existing db #{name}" return BDB::Hash.open(name, nil, "r+", 0600) end
# File lib/rbot/registry/bdb.rb, line 72 def method_missing(method, *args, &block) return @db.send(method, *args, &block) end