class Ant::Configuration::Loaders::Env
This class allows to load configurations from ENV It requires that all the vars are named with a common prefix It uses '__' as a delimiter to allow nested configurations
Examples¶ ↑
export CONFIG_ENV_VALUE=3 => { 'env_value' => '3' } export CONFIG_ENV_OBJ__VALUE=3 => { "env_obj" => { 'value' => '3' } }
Public Class Methods
new(env_prefix, manager, conf = ENV.to_h)
click to toggle source
# File lib/ant/configs/loaders/env.rb, line 14 def initialize(env_prefix, manager, conf = ENV.to_h) @env_prefix = env_prefix @manager = manager @env = conf end
Public Instance Methods
load!()
click to toggle source
Parses the configurations from ENV
# File lib/ant/configs/loaders/env.rb, line 21 def load! @env.select { |str, _| str.start_with?(@env_prefix) } .each_with_object({}) do |(k, v), h| # Remove ENV prefix and convert to downcase, then split by '__' clean_key = k.sub(/^#{@env_prefix}_?/, '').downcase.split('__') # recursively create the objects to set the config where it # should be recursive_set(h, clean_key, split_env_string(v)) end end