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