module Cumulus::Config
Public: A module that contains helper methods for the configuration classes.
When mixing in this module, make sure your class has a @node instance variable for what node in the json it expect to get config from, ie. “s3” or “iam”
Public Class Methods
# File lib/conf/Configuration.rb, line 22 def conf_dir @@conf_dir end
# File lib/conf/Configuration.rb, line 26 def conf_dir=(value) @@conf_dir = value end
# File lib/conf/Configuration.rb, line 14 def json @@json end
# File lib/conf/Configuration.rb, line 18 def json=(value) @@json = value end
Private Instance Methods
Internal: Take a path relative to the project root and turn it into an absolute path
relative_path - The String path from `conf_dir` to the desired file
Returns the absolute path as a String
# File lib/conf/Configuration.rb, line 39 def absolute_path(relative_path) if relative_path.start_with?("/") relative_path else File.join(@@conf_dir, relative_path) end end
Internal: Handle any KeyErrors that occur while getting a configuration value by printing out a message describing the missing key and exiting.
key - the full key to get ex. `s3.buckets.directory` allow_missing - if true we will return nil for missing values instead of exiting handler - a block that will do additional processing on the key. If nil,
the value is returned as is.
Returns the configuration value if successful
# File lib/conf/Configuration.rb, line 56 def conf(key, allow_missing = false, &handler) value = nil key.split(".").each do |part| if value value = value.fetch(part) else value = @@json.fetch(part) end end if handler handler.call(value) else value end rescue KeyError => e puts "Your configuration file is missing $.#{key}." if allow_missing nil else exit end end