5414: Do not blow up if local config file is empty.
[arvados.git] / services / api / config / initializers / zz_load_config.rb
1 $application_config = {}
2
3 %w(application.default application).each do |cfgfile|
4   path = "#{::Rails.root.to_s}/config/#{cfgfile}.yml"
5   if File.exists? path
6     yaml = ERB.new(IO.read path).result(binding)
7     confs = YAML.load(yaml)
8     # Ignore empty YAML file:
9     next if confs == false
10     $application_config.merge!(confs['common'] || {})
11     $application_config.merge!(confs[::Rails.env.to_s] || {})
12   end
13 end
14
15 Server::Application.configure do
16   nils = []
17   $application_config.each do |k, v|
18     # "foo.bar: baz" --> { config.foo.bar = baz }
19     cfg = config
20     ks = k.split '.'
21     k = ks.pop
22     ks.each do |kk|
23       cfg = cfg.send(kk)
24     end
25     if cfg.respond_to?(k.to_sym) and !cfg.send(k).nil?
26       # Config must have been set already in environments/*.rb.
27       #
28       # After config files have been migrated, this mechanism should
29       # be deprecated, then removed.
30     elsif v.nil?
31       # Config variables are not allowed to be nil. Make a "naughty"
32       # list, and present it below.
33       nils << k
34     else
35       cfg.send "#{k}=", v
36     end
37   end
38   if !nils.empty?
39     raise <<EOS
40 Refusing to start in #{::Rails.env.to_s} mode with missing configuration.
41
42 The following configuration settings must be specified in
43 config/application.yml:
44 * #{nils.join "\n* "}
45
46 EOS
47   end
48 end