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

conf_dir() click to toggle source
# File lib/conf/Configuration.rb, line 22
def conf_dir
  @@conf_dir
end
conf_dir=(value) click to toggle source
# File lib/conf/Configuration.rb, line 26
def conf_dir=(value)
  @@conf_dir = value
end
json() click to toggle source
# File lib/conf/Configuration.rb, line 14
def json
  @@json
end
json=(value) click to toggle source
# File lib/conf/Configuration.rb, line 18
def json=(value)
  @@json = value
end

Private Instance Methods

absolute_path(relative_path) click to toggle source

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
conf(key, allow_missing = false, &handler) click to toggle source

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
  if allow_missing
    nil
  else
    puts "Your configuration file is missing $.#{key}."
    exit
  end
end