2009-03-24 17:25:33 +01:00
|
|
|
# Loads and returns config and databases for selected foodcoop.
|
2010-03-20 13:45:58 +01:00
|
|
|
# TODO: When to use class or module. It seems this could also be a Foodsoft-class?
|
2009-03-24 17:01:10 +01:00
|
|
|
module Foodsoft
|
2010-03-20 13:45:58 +01:00
|
|
|
mattr_accessor :env, :config, :database
|
|
|
|
CONFIGS = YAML.load(File.read(RAILS_ROOT + "/config/app_config.yml"))
|
|
|
|
DATABASES = YAML.load(File.read(RAILS_ROOT + "/config/database.yml"))
|
2009-03-24 17:01:10 +01:00
|
|
|
|
2010-03-20 13:45:58 +01:00
|
|
|
class << self
|
|
|
|
def env=(env)
|
|
|
|
raise "No config or database for this environment (#{env}) available!" if CONFIGS[env].nil? or DATABASES[env].nil?
|
|
|
|
@@config = CONFIGS[env].symbolize_keys
|
|
|
|
@@database = DATABASES[env].symbolize_keys
|
|
|
|
@@env = env
|
|
|
|
end
|
2009-03-24 17:01:10 +01:00
|
|
|
end
|
|
|
|
end
|
2010-03-20 13:45:58 +01:00
|
|
|
# Initial load the default config and database from rails environment
|
|
|
|
Foodsoft.env = RAILS_ENV
|
2009-01-06 15:45:19 +01:00
|
|
|
|
2010-03-20 14:49:46 +01:00
|
|
|
# Set action mailer default host for url generating
|
2010-03-22 01:25:24 +01:00
|
|
|
url_options = {
|
|
|
|
:host => Foodsoft.config[:host],
|
|
|
|
:protocol => Foodsoft.config[:protocol]
|
2010-03-20 14:49:46 +01:00
|
|
|
}
|
2010-03-22 01:25:24 +01:00
|
|
|
url_options.merge!({:port => Foodsoft.config[:port]}) if Foodsoft.config[:port]
|
|
|
|
ActionMailer::Base.default_url_options = url_options
|
2010-03-20 14:49:46 +01:00
|
|
|
|
2009-01-06 15:45:19 +01:00
|
|
|
# Configuration of the exception_notification plugin
|
|
|
|
# Mailadresses are set in config/foodsoft.yaml
|
2009-03-24 17:25:33 +01:00
|
|
|
ExceptionNotifier.exception_recipients = Foodsoft.config[:notification]['error_recipients']
|
|
|
|
ExceptionNotifier.sender_address = Foodsoft.config[:notification]['sender_address']
|
2010-03-20 13:45:58 +01:00
|
|
|
ExceptionNotifier.email_prefix = Foodsoft.config[:notification]['email_prefix']
|
|
|
|
|