lib/hieracles/config.rb in hieracles-0.1.0 vs lib/hieracles/config.rb in hieracles-0.1.1

- old
+ new

@@ -1,13 +1,15 @@ require 'fileutils' +require 'json' +require 'yaml' module Hieracles # configuration singleton module Config extend self - attr_reader :extraparams, :server, :classpath, + attr_reader :extraparams, :server, :classpath, :facts, :modulepath, :hierafile, :basepath, :encpath, :format def load(options) @optionfile = options[:config] || defaultconfig @extraparams = extract_params(options[:params]) @@ -18,10 +20,13 @@ @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' @format = (options[:format] || values['format'] || 'console').capitalize + facts_file = options[:yaml_facts] || options[:json_facts] + facts_format = options[:json_facts] ? :json : :yaml + @facts = (facts_file && load_facts(facts_file, facts_format)) || {} end def initconfig(file) FileUtils.mkdir_p(File.dirname(file)) File.open(file, 'w') do |f| @@ -48,9 +53,17 @@ end end def path(what) File.join(@basepath, 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 end end