From d488c5f3be065eaf3404c8fdba0e9ea6fb53cb1d Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Mon, 2 Jan 2012 13:03:45 +0100 Subject: [PATCH] Really fixed config file location; added some type checking --- stoptime.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index 1353df1..64a3609 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -97,7 +97,7 @@ module StopTime::Models include Singleton # The default configuation file. (FIXME: shouldn't be hardcoded!) - ConfigFile = File.basename(__FILE__) + "/config.yaml" + ConfigFile = File.dirname(__FILE__) + "/config.yaml" # The default configuration. Note that the configuration of the root # will be merged with this configuration. DefaultConfig = { "invoice_id" => "%Y%N", @@ -119,8 +119,15 @@ module StopTime::Models rescue => e $stderr.puts "E: couldn't read configuration file: #{e}" end - # Merge the loaded config with the default config. - @config = DefaultConfig.dup.merge cfg unless cfg.nil? + # Merge the loaded config with the default config (if it's a Hash) + case cfg + when Hash + @config = DefaultConfig.dup.merge cfg if cfg + when nil, false + # It's ok, it is empty. + else + $stderr.puts "W: wrong format detected in configuration file!" + end end # Reloads the configuration file.