Commit 8608f10b133549966e000b6c983d9aa1edd1bdd6

Authored by Nathan Broadbent
1 parent c8d37823
Exists in master and in 1 other branch production

Set default settings from config.example.yml if key is missing from config.yml

Showing 1 changed file with 9 additions and 3 deletions   Show diff stats
config/initializers/_load_config.rb
... ... @@ -20,12 +20,12 @@ if ENV['HEROKU']
20 20 end
21 21  
22 22 # Use example config for test environment.
23   -config_file = Rails.root.join('config', Rails.env == "test" ? "config.example.yml" : "config.yml")
  23 +default_config_file = Rails.root.join("config", "config.example.yml")
  24 +config_file = Rails.env == "test" ? default_config_file : Rails.root.join("config", "config.yml")
24 25  
25 26 # Load config if config file exists.
26 27 if File.exists?(config_file)
27   - yaml = File.read(config_file)
28   - config = YAML.load(yaml)
  28 + config = YAML.load_file(config_file)
29 29 config.merge!(config.delete(Rails.env)) if config.has_key?(Rails.env)
30 30 config.each do |k,v|
31 31 Errbit::Config.send("#{k}=", v)
... ... @@ -35,6 +35,12 @@ elsif not ENV['HEROKU']
35 35 raise "Please copy 'config/config.example.yml' to 'config/config.yml' and configure your settings."
36 36 end
37 37  
  38 +# Set default settings from config.example.yml if key is missing from config.yml
  39 +default_config = YAML.load_file(default_config_file)
  40 +default_config.each do |k,v|
  41 + Errbit::Config.send("#{k}=", v) if Errbit::Config.send(k) === nil
  42 +end
  43 +
38 44 # Set SMTP settings if given.
39 45 if smtp = Errbit::Config.smtp_settings
40 46 Errbit::Application.config.action_mailer.smtp_settings = smtp
... ...