X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Frbot%2Fconfig.rb;h=e6145a82ee95637d6a31528bf2a89598c6e0e1b8;hb=cf8324728c4b427d1955a7ed3ba65c05e2545bc3;hp=207264bf5e6ab6f081cd5bee31a903dc72ad4792;hpb=9487a04ec88c8c55e8097664dcc74e79e87162d6;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb index 207264bf..e6145a82 100644 --- a/lib/rbot/config.rb +++ b/lib/rbot/config.rb @@ -186,7 +186,7 @@ module Config unless newval.include? val newval << val validate_item(val) or raise ArgumentError, "invalid item: #{val}" - validate(newval) or raise ArgumentError, "invalid value: #{newval.to_s}" + validate(newval) or raise ArgumentError, "invalid value: #{newval.inspect}" set(newval) end end @@ -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! #{$!}"