Class: Onering::Config
- Inherits:
-
Object
- Object
- Onering::Config
- Defined in:
- lib/onering/config.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{}
- DEFAULT_OPTIONS_FILE =
["~/.onering/cli.yml", "~/.onering/key.yml", "/etc/onering/cli.yml", "/etc/onering/key.yml"]
Class Method Summary collapse
- .get(key, default = nil) ⇒ Object
- .load(configfile = nil, config = {}) ⇒ Object
- .set(key, value) ⇒ Object
- .unset(key) ⇒ Object
Class Method Details
.get(key, default = nil) ⇒ Object
49 50 51 |
# File 'lib/onering/config.rb', line 49 def get(key, default=nil) @_config.get(key, default) end |
.load(configfile = nil, config = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/onering/config.rb', line 10 def load(configfile=nil, config={}) if configfile.nil? configfile = [] else # recursively grab all .yml files if directory is specified configfile = (File.directory?(configfile) ? Dir.glob(File.join(configfile, "**", "*.yml")).sort : [configfile]) end # list all existing config files from least specific to most @_configfiles = (configfile + DEFAULT_OPTIONS_FILE).compact.select{|i| (File.exists?(File.(i)) rescue false) }.reverse # merge all config files with more-specific values overriding less-specific ones @_config ||= DEFAULT_CONFIG @_configfiles_seen ||= Set.new() # only load files we haven't seen before (@_configfiles - @_configfiles_seen.to_a).each do |i| c = YAML.load(File.read(File.(i))) rescue {} if c and not c.empty? Onering::Logger.info("Loading config file at #{File.(i) rescue i}", "Onering::Config") @_config.deep_merge!(c) end @_configfiles_seen << i end # settings specified in the library override everything unless config.empty? Onering::Logger.debug("Merging settings specified in library instantiation", "Onering::Config") @_config.deep_merge!(config.compact) end return @_config end |
.set(key, value) ⇒ Object
53 54 55 |
# File 'lib/onering/config.rb', line 53 def set(key, value) @_config.set(key, value) end |
.unset(key) ⇒ Object
57 58 59 |
# File 'lib/onering/config.rb', line 57 def unset(key) @_config.unset(key) end |