Class: Irc::DBHash
Overview
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
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(bot, key, absfilename = false) ⇒ DBHash
constructor
- absfilename
-
use
key
as an actual filename, don’t prepend the bot’s config path and don’t append “.db”.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(bot, key, absfilename = false) ⇒ DBHash
- absfilename
-
use
key
as an actual filename, don’t prepend the bot’s config path and don’t append “.db”
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rbot/dbhash.rb', line 52 def initialize(bot, key, absfilename=false) @bot = bot @key = key if absfilename && File.exist?(key) # db already exists, use it @db = DBHash.open_db(key) elsif File.exist?(@bot.botclass + "/#{key}.db") # db already exists, use it @db = DBHash.open_db(@bot.botclass + "/#{key}.db") elsif absfilename # create empty db @db = DBHash.create_db(key) else # create empty db @db = DBHash.create_db(@bot.botclass + "/#{key}.db") end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
70 71 72 |
# File 'lib/rbot/dbhash.rb', line 70 def method_missing(method, *args, &block) return @db.send(method, *args, &block) end |