Commit c488c2061dcb426ec5c6ad43c62349aec82e4426

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

Added more comments to initializers/_load_config. Raise an error if config.yml i…

…s missing on a standard deployment
Showing 1 changed file with 7 additions and 1 deletions   Show diff stats
config/initializers/_load_config.rb
@@ -2,6 +2,7 @@ require 'ostruct' @@ -2,6 +2,7 @@ require 'ostruct'
2 2
3 Errbit::Config = OpenStruct.new 3 Errbit::Config = OpenStruct.new
4 4
  5 +# If Errbit is running on Heroku, config can be set from environment variables.
5 if ENV['HEROKU'] 6 if ENV['HEROKU']
6 Errbit::Config.host = ENV['ERRBIT_HOST'] 7 Errbit::Config.host = ENV['ERRBIT_HOST']
7 Errbit::Config.email_from = ENV['ERRBIT_EMAIL_FROM'] 8 Errbit::Config.email_from = ENV['ERRBIT_EMAIL_FROM']
@@ -23,8 +24,10 @@ if ENV['HEROKU'] @@ -23,8 +24,10 @@ if ENV['HEROKU']
23 } 24 }
24 end 25 end
25 26
  27 +# Use example config for test environment.
26 config_file = Rails.root.join('config', Rails.env == "test" ? "config.example.yml" : "config.yml") 28 config_file = Rails.root.join('config', Rails.env == "test" ? "config.example.yml" : "config.yml")
27 29
  30 +# Load config if config file exists.
28 if File.exists?(config_file) 31 if File.exists?(config_file)
29 yaml = File.read(config_file) 32 yaml = File.read(config_file)
30 config = YAML.load(yaml) 33 config = YAML.load(yaml)
@@ -32,9 +35,12 @@ if File.exists?(config_file) @@ -32,9 +35,12 @@ if File.exists?(config_file)
32 config.each do |k,v| 35 config.each do |k,v|
33 Errbit::Config.send("#{k}=", v) 36 Errbit::Config.send("#{k}=", v)
34 end 37 end
  38 +# Raise an error if we are not running tests, not running on Heroku, and config.yml doesn't exist.
  39 +elsif not ENV['HEROKU']
  40 + raise "Please copy 'config/config.example.yml' to 'config/config.yml' and configure your settings."
35 end 41 end
36 42
37 -# Set SMTP settings if given, but retain defaults if not. 43 +# Set SMTP settings if given.
38 if smtp = Errbit::Config.smtp_settings 44 if smtp = Errbit::Config.smtp_settings
39 Errbit::Application.config.action_mailer.smtp_settings = smtp 45 Errbit::Application.config.action_mailer.smtp_settings = smtp
40 end 46 end