module Figroll

A simple universal ENV-focused configuration library

Constants

VERSION

Public Class Methods

configure(config_file) click to toggle source

Given a config file, set up Figroll for ENV consumption @param config_file [String] the figroll configuration for your app

# File lib/figroll.rb, line 9
def self.configure(config_file)
  setup

  # Load the config file
  config.load_file(config_file)

  # Import the environment configuration from the config
  storage.import(config.data)

  # Import the actual ENV hash
  storage.import(ENV)

  # verify all required variables are set
  validate_configuration
end
fetch(key) click to toggle source

Retrieve the value of an environment configuration variable. The key may be either a String or a Symbol, non-case-sensitive. For example, these all reference the same value:

  • 'i am a variable'

  • 'i_am_a_variable'

  • 'I_AM_A_VARIABLE'

  • :i_am_a_variable

@param key [String, Symbol] the stringified or symbolized name of the

variable for which you want to know the value.

@return [String] the value of the variable when Figroll was configured @raise [RuntimeError] if the varible was not known at configuration time

# File lib/figroll.rb, line 36
def self.fetch(key)
  storage.fetch(key)
end

Private Class Methods

config() click to toggle source
# File lib/figroll.rb, line 47
def config
  @config
end
environment() click to toggle source
# File lib/figroll.rb, line 67
def environment
  config.environment
end
keys() click to toggle source
# File lib/figroll.rb, line 63
def keys
  storage.keys
end
required() click to toggle source
# File lib/figroll.rb, line 59
def required
  config.required
end
setup() click to toggle source
# File lib/figroll.rb, line 71
def setup
  @config = Config.new
  @storage = Storage.new
end
storage() click to toggle source
# File lib/figroll.rb, line 43
def storage
  @storage
end
validate_configuration() click to toggle source
# File lib/figroll.rb, line 51
def validate_configuration
  return nil if required.length == 0
  return nil if (keys - required).length == keys.length - required.length

  missing = required.reject {|key| keys.include?(key)}
  raise "Required variables not set: #{missing.sort.join(', ')}"
end