Really fixed config file location; added some type checking
This commit is contained in:
parent
217985afc8
commit
d488c5f3be
13
stoptime.rb
13
stoptime.rb
|
@ -97,7 +97,7 @@ module StopTime::Models
|
||||||
include Singleton
|
include Singleton
|
||||||
|
|
||||||
# The default configuation file. (FIXME: shouldn't be hardcoded!)
|
# 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
|
# The default configuration. Note that the configuration of the root
|
||||||
# will be merged with this configuration.
|
# will be merged with this configuration.
|
||||||
DefaultConfig = { "invoice_id" => "%Y%N",
|
DefaultConfig = { "invoice_id" => "%Y%N",
|
||||||
|
@ -119,8 +119,15 @@ module StopTime::Models
|
||||||
rescue => e
|
rescue => e
|
||||||
$stderr.puts "E: couldn't read configuration file: #{e}"
|
$stderr.puts "E: couldn't read configuration file: #{e}"
|
||||||
end
|
end
|
||||||
# Merge the loaded config with the default config.
|
# Merge the loaded config with the default config (if it's a Hash)
|
||||||
@config = DefaultConfig.dup.merge cfg unless cfg.nil?
|
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
|
end
|
||||||
|
|
||||||
# Reloads the configuration file.
|
# Reloads the configuration file.
|
||||||
|
|
Loading…
Reference in New Issue