Class: HieraSimulator::Config
- Inherits:
-
Object
- Object
- HieraSimulator::Config
- Defined in:
- lib/hiera-simulator/config.rb
Overview
Load the configuration for the Hiera simulator
The order in which files are read in are:
-
$CWD/.hiera-simulator.yaml
-
$HOME/.hiera-simulator.yaml
-
/etc/hiera-simulator.yaml
The reading of the configuration values happens very much like in Hiera itself, where the first time a key is seen, subsequent occurrences of that key are ignored.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#get(key, default = nil) ⇒ Object
Get - shorthand method to retrieve a particular key from the config hash.
-
#initialize(overrides = {}) ⇒ Config
constructor
Constructor.
-
#merge!(newhash) ⇒ Object
Merge! - Merge a hash.
-
#raise_missing_parameter(parameter) ⇒ Object
Throw “Missing Parameter” error.
-
#validate ⇒ Object
Validate configuration.
Constructor Details
#initialize(overrides = {}) ⇒ Config
Constructor
18 19 20 21 22 23 |
# File 'lib/hiera-simulator/config.rb', line 18 def initialize(overrides = {}) @home_dir = overrides.fetch(:home_dir, ENV['HOME']) @global_configfile = overrides.fetch(:global_config, '/etc/hiera-simulator.yaml') @working_dir = overrides.fetch(:cwd) { |_x| File.absolute_path(Dir.getwd) } @config = overrides.fetch(:config) { |_x| retrieve_config } end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/hiera-simulator/config.rb', line 14 def config @config end |
Instance Method Details
#get(key, default = nil) ⇒ Object
Get - shorthand method to retrieve a particular key from the config hash
29 30 31 |
# File 'lib/hiera-simulator/config.rb', line 29 def get(key, default = nil) @config.fetch(key, @config.fetch(key.to_s, @config.fetch(key.to_sym, default))) end |
#merge!(newhash) ⇒ Object
Merge! - Merge a hash
35 36 37 |
# File 'lib/hiera-simulator/config.rb', line 35 def merge!(newhash) @config.merge!(newhash) end |
#raise_missing_parameter(parameter) ⇒ Object
Throw “Missing Parameter” error
45 46 47 48 49 50 51 |
# File 'lib/hiera-simulator/config.rb', line 45 def raise_missing_parameter(parameter) errmsg = "\n\nERROR!!! A required parameter (#{parameter}) was missing.\n" errmsg += "Tried these files: #{filelist.inspect}\n" errmsg += "(None of these files could be found)\n" if retrieve_config.empty? errmsg += "Please see https://github.com/kpaulisse/hiera-simulator/blob/master/doc/troubleshooting.rb for more.\n\n" raise ConfigError, errmsg end |
#validate ⇒ Object
Validate configuration
40 41 42 |
# File 'lib/hiera-simulator/config.rb', line 40 def validate raise_no_config_files_found if config.empty? end |