Class: Irc::DBHash
- Defined in:
- lib/rbot/registry/tc.rb,
lib/rbot/registry/bdb.rb
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”
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rbot/registry/tc.rb', line 40 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
60 61 62 |
# File 'lib/rbot/registry/tc.rb', line 60 def method_missing(method, *args, &block) return @db.send(method, *args, &block) end |