summaryrefslogtreecommitdiff
path: root/lib/rbot/config.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-02-15 01:30:51 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-02-15 02:06:27 +0100
commit91a9024e21ec8b429605a036b5c9193442a580e3 (patch)
treef1524dd5595a80e32d0702c0d8939b1001c695fb /lib/rbot/config.rb
parent38be7f6511447d98780a069bccefecd933238e30 (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/config.rb')
-rw-r--r--lib/rbot/config.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb
index 4f81c695..e6145a82 100644
--- a/lib/rbot/config.rb
+++ b/lib/rbot/config.rb
@@ -262,9 +262,10 @@ module Config
return unless @bot
@changed = false
- if(File.exist?("#{@bot.botclass}/conf.yaml"))
+ conf = @bot.path 'conf.yaml'
+ if File.exist? conf
begin
- newconfig = YAML::load_file("#{@bot.botclass}/conf.yaml")
+ newconfig = YAML::load_file conf
newconfig.each { |key, val|
@config[key.to_sym] = val
}
@@ -327,8 +328,10 @@ module Config
return
end
begin
+ conf = @bot.path 'conf.yaml'
+ fnew = conf + '.new'
debug "Writing new conf.yaml ..."
- File.open("#{@bot.botclass}/conf.yaml.new", "w") do |file|
+ File.open(fnew, "w") do |file|
savehash = {}
@config.each { |key, val|
savehash[key.to_s] = val
@@ -336,8 +339,7 @@ module Config
file.puts savehash.to_yaml
end
debug "Officializing conf.yaml ..."
- File.rename("#{@bot.botclass}/conf.yaml.new",
- "#{@bot.botclass}/conf.yaml")
+ File.rename(fnew, conf)
@changed = false
rescue => e
error "failed to write configuration file conf.yaml! #{$!}"