13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/quiverstaskrunner/helpers/settingshelper.rb', line 13
def get_settings(filepath, env={}, options={})
verbose = (defined? ARGV) && (!ARGV.nil?) && (!ARGV.empty?) && (ARGV.detect { |x| x == "-v" })
environment = env.is_a?(Hash) ? "defaults" : env
file_contents = open(filepath).read
YAML.load(ERB.new(file_contents).result).to_hash
all_settings = YAML.load(ERB.new(file_contents).result).to_hash
settings = all_settings[environment]
if verbose
puts "settings for the '#{filepath}' file and the '#{environment}' environment:".colorize(:yellow)
puts CliHelper.pretty_print(settings)
end
injected_settings = SettingsHelper.get_cli_settings(options)
if verbose
puts "Injected settings from the CLI:".colorize(:yellow)
puts CliHelper.pretty_print(injected_settings)
end
final_settings =
if !injected_settings.empty?
Hash[*settings.map { |k,v| (injected_settings.has_key?(k) ? [k, injected_settings[k]] : [k, v]) }.flatten ]
else
settings
end
if verbose
puts "Final settings:".colorize(:yellow)
puts CliHelper.pretty_print(final_settings)
end
return final_settings
end
|