Class: Kitsune::Kit::Configuration::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/kitsune/kit/configuration.rb

Instance Method Summary collapse

Constructor Details

#initialize(root: Dir.pwd, env: ENV, config_path: nil, validate_secrets: true) ⇒ Loader

Returns a new instance of Loader.



219
220
221
222
223
224
# File 'lib/kitsune/kit/configuration.rb', line 219

def initialize(root: Dir.pwd, env: ENV, config_path: nil, validate_secrets: true)
  @root = Pathname(root).expand_path
  @env = env
  @config_path = config_path ? Pathname(config_path).expand_path : @root.join(".kitsune/config.yml")
  @validate_secrets = validate_secrets
end

Instance Method Details

#load(environment: nil, overrides: {}) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/kitsune/kit/configuration.rb', line 226

def load(environment: nil, overrides: {})
  selected_environment = (environment || @env["KITSUNE_ENV"] || selected_environment_from_file ||
                          "development").to_s
  unless selected_environment.match?(/\A[a-z0-9][a-z0-9_-]*\z/)
    raise Errors::ConfigurationError, "environment name has an invalid format"
  end

  project = load_yaml(@config_path, required: true)
  environment_config = load_yaml(@root.join(".kitsune/environments/#{selected_environment}.yml"),
                                 required: false)
  combined = deep_merge(DEFAULTS, project)
  combined = deep_merge(combined, environment_config)
  combined = apply_environment(combined)
  combined = deep_merge(combined, stringify_keys(overrides))
  build(combined, selected_environment)
end