Class: Ridgepole::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ridgepole/cli/config.rb

Class Method Summary collapse

Class Method Details

.load(config, env = 'development', spec_name = '') ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ridgepole/cli/config.rb', line 9

def load(config, env = 'development', spec_name = '')
  config = ENV.fetch(Regexp.last_match(1)) if config =~ /\Aenv:(.+)\z/

  parsed_config = if File.exist?(config)
                    parse_config_file(config)
                  elsif (expanded = File.expand_path(config)) && File.exist?(expanded)
                    parse_config_file(expanded)
                  else
                    YAML.safe_load(
                      ERB.new(config).result,
                      permitted_classes: [],
                      permitted_symbols: [],
                      aliases: true
                    )
                  end

  parsed_config = parse_database_url(config) unless parsed_config.is_a?(Hash)

  parsed_config = parsed_config.fetch(env.to_s) if parsed_config.key?(env.to_s)

  if parsed_config.key?(spec_name.to_s)
    parsed_config.fetch(spec_name.to_s)
  else
    parsed_config
  end
end