Module: CleanConfig::Configurable

Defined in:
lib/clean_config/configurable.rb

Overview

Module to help initialize and gain access to CleanConfig::Configuration object

Class Method Summary collapse

Class Method Details

.included(_parent) ⇒ Object

Initialize the CleanConfig::Configuration object Reads in from default config/config.yml file based on project root directory


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/clean_config/configurable.rb', line 11

def included(_parent)
  log = ConfLogger.new(STDOUT)

  # calling_file is the file name of the Ruby code that is our parent in the call stack.
  calling_file = caller.first.split(':').first
  log.debug("calling_file: #{calling_file}")
  config_path = Configuration.resolve_config_path(calling_file)

  if File.exist?(config_path)
    Configuration.instance.add!(config_path)
    log.debug("Reading configuration from #{config_path}")
    begin
      Configuration.instance.add!(config_path)
    rescue InvalidConfigException
      log.warn("Read configuration from #{config_path}, but configuration not valid. Ignoring, check your config")
    end
  else
    log.debug("Expected config directory #{config_path} not found. Not loading configuration")
  end
end