lib/hieracles/config.rb in hieracles-0.1.7 vs lib/hieracles/config.rb in hieracles-0.2.0

- old
+ new

@@ -15,15 +15,15 @@ def load(options) @optionfile = options[:config] || defaultconfig @extraparams = extract_params(options[:params]) values = get_config(@optionfile) @server = values['server'] - @classpath = values['classpath'] - @modulepath = values['modulepath'] || 'modules' - @encpath = options[:encpath] || values['encpath'] || 'enc' - @basepath = File.expand_path(options[:basepath] || values['basepath'] || '.') - @hierafile = options[:hierafile] || values['hierafile'] || 'hiera.yaml' + @basepath = File.expand_path(options[:basepath] || values['basepath'] || values['localpath'] || '.') + @classpath = build_path(values['classpath']) + @modulepath = resolve_path(values['modulepath'] || 'modules') + @encpath = resolve_path(options[:encpath] || values['encpath'] || 'enc') + @hierafile = resolve_path(options[:hierafile] || values['hierafile'] || 'hiera.yaml') @format = (options[:format] || values['format'] || 'console').capitalize facts_file = options[:yaml_facts] || options[:json_facts] facts_format = options[:json_facts] ? :json : :yaml @scope = sym_keys((facts_file && load_facts(facts_file, facts_format)) || values['defaultscope'] || {}) @interactive = options[:interactive] || values['interactive'] @@ -59,18 +59,32 @@ a end end def path(what) - File.join(@basepath, send(what.to_sym)) + send(what.to_sym) end def load_facts(file, format) if format == :json JSON.parse(File.read(file)) else YAML.load_file(file) end + end + + def resolve_path(path) + if File.exists?(File.expand_path(path)) + File.expand_path(path) + elsif File.exists?(File.expand_path(File.join(@basepath, path))) + File.expand_path(File.join(@basepath, path)) + else + raise IOError, "File #{path} not found." + end + end + + def build_path(path) + File.expand_path(File.join(@basepath, path)) end end end