class Locd::Config
A hash-like container providing access to a layered tree of config values sourced from `YAML` files and `ENV` vars.
Keys
Config
keys are arrays of strings that
Constants
- DEFAULT_CONFIG_PATH
Absolute path to the default config file (`//config/default.yml`).
Has to be defined as a constant because no other config is loaded before it and it contains the ENV var prefix.
@return [Pathname]
- DEV_CONFIG_PATH
Absolute path to the dev override config, which will be loaded last if it exists.
@return [Pathname]
- KEY_SEPARATOR
What to split string keys into key path segments on.
@return [String]
Attributes
Absolute path to the built-in default configuration file in use.
@return [Pathname]
TODO document `file_loads` attribute.
@return [Array<FileLoad>]
Public Class Methods
Instantiate a new `Locd::Config`.
# File lib/locd/config.rb, line 106 def initialize default_config_path: DEFAULT_CONFIG_PATH, dev_config_path: DEV_CONFIG_PATH @default_config_path = default_config_path.to_pn @dev_config_path = dev_config_path.to_pn @file_loads = [] @from_files = {} begin load_file! default_config_path, name: :default rescue StandardError => error logger.error "Failed to load default config!", error end begin if user_config_path.exist? load_file! user_config_path, name: :user end rescue Exception => error logger.error "Failed to load user config!", error end begin if dev_config_path && dev_config_path.exist? load_file! dev_config_path, name: :dev end rescue Exception => error logger.error "Failed to load dev config!", error end end
Protected Instance Methods
Load a `YAML` config file into the config.
@param [Pathname | String] path
Path to file.
@return [nil]
# File lib/locd/config.rb, line 152 def load_file! path, name: nil parse = path.to_pn.read.thru { |str| YAML.safe_load str } post = @from_files.deep_merge parse @file_loads << FileLoad.new( name: name, path: path, prev: @from_files, parse: parse, post: post, ) @from_files = post nil end