diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-15 01:30:51 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-15 02:06:27 +0100 |
commit | 91a9024e21ec8b429605a036b5c9193442a580e3 (patch) | |
tree | f1524dd5595a80e32d0702c0d8939b1001c695fb /lib/rbot/plugins.rb | |
parent | 38be7f6511447d98780a069bccefecd933238e30 (diff) |
+ @bot.path and datafile methods
We provide two methods that make it more simple and elegant for
botmodules to define paths relative to the bot's own directory
(botclass) and to the BotModule's (assumed) non-registry directory.
The first method is Irc::Bot#path(), which joins its arguments with the
botclass. This method can be used to access datafiles in the bot
directory with a much cleaner syntax; and since it uses File.join, the
resulting paths are also properly formatted on each platform, which
doesn't hurt.
Each BotModule now also carries a dirname() method that should return the
directory under botclass that holds the BotModule's datafiles. dirname()
defaults to the BotModule's name(), but it can be overridden, e.g. for
backwards compatibility (see the patch for the quotes plugin), or
for BotModules that share their datafiles.
Datafiles can be accessed using the BotModule#datafile() method that
joins the botclass, the dirname() and whatever other argument is passed.
Diffstat (limited to 'lib/rbot/plugins.rb')
-rw-r--r-- | lib/rbot/plugins.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index 4d51cfc5..9d5523e4 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -349,6 +349,20 @@ module Plugins @bot.plugins.mark_priorities_dirty end end + + # Directory name to be joined to the botclass to access data files. By + # default this is the plugin name itself, but may be overridden, for + # example by plugins that share their datafiles or for backwards + # compatibilty + def dirname + name + end + + # Filename for a datafile built joining the botclass, plugin dirname and + # actual file name + def datafile(*fname) + @bot.path dirname, *fname + end end # A CoreBotModule is a BotModule that provides core functionality. |