Class | Irc::DBHash |
In: |
lib/rbot/registry/bdb.rb
lib/rbot/registry/tc.rb |
Parent: | Object |
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 76: def DBHash.create_db(name) 77: debug "DBHash: creating empty db #{name}" 78: return BDB::Hash.open(name, nil, 79: BDB::CREATE | BDB::EXCL, 0600) 80: end
# File lib/rbot/registry/tc.rb, line 64 64: def DBHash.create_db(name) 65: debug "DBHash: creating empty db #{name}" 66: return BDB::Hash.open(name, nil, 67: BDB::CREATE | BDB::EXCL, 0600) 68: end
absfilename: | 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 52: def initialize(bot, key, absfilename=false) 53: @bot = bot 54: @key = key 55: relfilename = @bot.path key 56: relfilename << '.db' 57: if absfilename && File.exist?(key) 58: # db already exists, use it 59: @db = DBHash.open_db(key) 60: elsif absfilename 61: # create empty db 62: @db = DBHash.create_db(key) 63: elsif File.exist? relfilename 64: # db already exists, use it 65: @db = DBHash.open_db relfilename 66: else 67: # create empty db 68: @db = DBHash.create_db relfilename 69: end 70: end
absfilename: | use key as an actual filename, don‘t prepend the bot‘s config path and don‘t append ".db" |
# File lib/rbot/registry/tc.rb, line 40 40: def initialize(bot, key, absfilename=false) 41: @bot = bot 42: @key = key 43: relfilename = @bot.path key 44: relfilename << '.db' 45: if absfilename && File.exist?(key) 46: # db already exists, use it 47: @db = DBHash.open_db(key) 48: elsif absfilename 49: # create empty db 50: @db = DBHash.create_db(key) 51: elsif File.exist? relfilename 52: # db already exists, use it 53: @db = DBHash.open_db relfilename 54: else 55: # create empty db 56: @db = DBHash.create_db relfilename 57: end 58: end
# File lib/rbot/registry/bdb.rb, line 82 82: def DBHash.open_db(name) 83: debug "DBHash: opening existing db #{name}" 84: return BDB::Hash.open(name, nil, "r+", 0600) 85: end
# File lib/rbot/registry/tc.rb, line 70 70: def DBHash.open_db(name) 71: debug "DBHash: opening existing db #{name}" 72: return BDB::Hash.open(name, nil, "r+", 0600) 73: end
# File lib/rbot/registry/bdb.rb, line 72 72: def method_missing(method, *args, &block) 73: return @db.send(method, *args, &block) 74: end