module MediTAF::Utils::Configuration
Public Class Methods
[](key)
click to toggle source
backward compatibility for older style references of Configuration['xxx']
# File lib/MediTAF/utils/configuration.rb, line 38 def [](key) (key == 'modules') ? @modules : @modules['modules'][key] end
new(filepath = nil)
click to toggle source
@param filepath [String] path/to/file @raise [ConfigurationNotFoundError] when YAML cannot load the file
# File lib/MediTAF/utils/configuration.rb, line 11 def new(filepath = nil) filepath ||= Dir.glob(File.join("**", "meditaf_config.yml")).first yml_hashes = [] # load main yaml file yml_hashes << YAML.load_file(filepath) raise FileEmpty, "#{filepath} is empty. Nothing to config, YAY!" unless yml_hashes[0] # load additional yml files if yml_hashes[0]['modules']['config_files'] yml_hashes[0]['modules']['config_files'].split(/ *, */).each { |f| yml_hashes << YAML.load_file(f) } modules = yml_hashes.shift added = yml_hashes.each_with_object({}) { |oh, nh| nh.merge!(oh) } modules['modules'].merge!(added) end modules ||= yml_hashes[0] # merge all yml hashes into one hash @modules = Settings.new('modules', modules['modules'] ) rescue Errno::ENOENT => e raise FileNotFound, "missing configuration. check you have meditaf_config in the 'config' or " + "project root directory and is valid." rescue Psych::SyntaxError => e raise Error, "Configuration Error : #{e}" end