8784: Fix test for latest firefox.
[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, deserialize_symbols: true)
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 v.nil? and cfg.respond_to?(k) and !cfg.send(k).nil?
27       # Config is nil in *.yml, but has been set already in
28       # environments/*.rb (or has a Rails default). Don't overwrite
29       # the default/upstream config with nil.
30       #
31       # After config files have been migrated, this mechanism should
32       # be removed.
33       Rails.logger.warn <<EOS
34 DEPRECATED: Inheriting config.#{ks.join '.'} from Rails config.
35             Please move this config into config/application.yml.
36 EOS
37     elsif v.nil?
38       # Config variables are not allowed to be nil. Make a "naughty"
39       # list, and present it below.
40       nils << k
41     else
42       cfg.send "#{k}=", v
43     end
44   end
45   if !nils.empty?
46     raise <<EOS
47 Refusing to start in #{::Rails.env.to_s} mode with missing configuration.
48
49 The following configuration settings must be specified in
50 config/application.yml:
51 * #{nils.join "\n* "}
52
53 EOS
54   end
55 end