From 54275a0576b05813e78aa7707111db3411602048 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Tue, 25 Feb 2014 12:59:24 +0200 Subject: Fix crashes on missing config We now merge user config with bootstrap config ensuring all configuratio options are set even if not in configuratatin. Allowing us to add new configuration options, without needing for users to touch their existing configuration. All default values are still written to user config when ever CFG.save is called, which means when you change your output/input/source models and configuration is missing, instead of just adding the configuration needed for that particular module, it'll save full config to file. Don't really think that is a bug, but might be something to fix later on with maybe parameter to 'save'. Which would load user config, merge it with 'save' argument level and save user config. But unless someone is bothered by it, I won't do it. This commit fixes #1 --- lib/oxidized/config/core.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/oxidized/config/core.rb') diff --git a/lib/oxidized/config/core.rb b/lib/oxidized/config/core.rb index c2cde58..9b93d91 100644 --- a/lib/oxidized/config/core.rb +++ b/lib/oxidized/config/core.rb @@ -11,17 +11,22 @@ module Oxidized # load config from file or bootstrap with built-ins def load if File.exists? @file - marshal_load YAML.load_file @file + cfg = YAML.load_file @file + marshal_load self.to_h.merge(cfg) else - require 'oxidized/config/bootstrap' + save end end + def defaults + require 'oxidized/config/bootstrap' + end # save config to file def save File.write @file, YAML.dump(marshal_dump) end end CFG = Config.new + CFG.defaults CFG.load Log.file = CFG.log if CFG.log Log.level = Logger::INFO unless CFG.debug -- cgit v1.2.1