Merge branch 'master' into 2257-inequality-conditions
[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     $application_config.merge!(confs['common'] || {})
9     $application_config.merge!(confs[::Rails.env.to_s] || {})
10   end
11 end
12
13 Server::Application.configure do
14   nils = []
15   $application_config.each do |k, v|
16     # "foo.bar: baz" --> { config.foo.bar = baz }
17     cfg = config
18     ks = k.split '.'
19     k = ks.pop
20     ks.each do |kk|
21       cfg = cfg.send(kk)
22     end
23     if cfg.respond_to?(k.to_sym) and !cfg.send(k).nil?
24       # Config must have been set already in environments/*.rb.
25       #
26       # After config files have been migrated, this mechanism should
27       # be deprecated, then removed.
28     elsif v.nil?
29       # Config variables are not allowed to be nil. Make a "naughty"
30       # list, and present it below.
31       nils << k
32     else
33       cfg.send "#{k}=", v
34     end
35   end
36   if !nils.empty?
37     raise <<EOS
38 Refusing to start in #{::Rails.env.to_s} mode with missing configuration.
39
40 The following configuration settings must be specified in
41 config/application.yml:
42 * #{nils.join "\n* "}
43
44 EOS
45   end
46 end