annotate lib/redmine/.svn/text-base/configuration.rb.svn-base @ 210:0579821a129a

Update to Redmine trunk rev 4802
author Chris Cannam
date Tue, 08 Feb 2011 13:51:46 +0000
parents
children 051f544170fe
rev   line source
Chris@210 1 # Redmine - project management software
Chris@210 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@210 3 #
Chris@210 4 # This program is free software; you can redistribute it and/or
Chris@210 5 # modify it under the terms of the GNU General Public License
Chris@210 6 # as published by the Free Software Foundation; either version 2
Chris@210 7 # of the License, or (at your option) any later version.
Chris@210 8 #
Chris@210 9 # This program is distributed in the hope that it will be useful,
Chris@210 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@210 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@210 12 # GNU General Public License for more details.
Chris@210 13 #
Chris@210 14 # You should have received a copy of the GNU General Public License
Chris@210 15 # along with this program; if not, write to the Free Software
Chris@210 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@210 17
Chris@210 18 module Redmine
Chris@210 19 module Configuration
Chris@210 20
Chris@210 21 # Configuration default values
Chris@210 22 @defaults = {
Chris@210 23 'email_delivery' => nil
Chris@210 24 }
Chris@210 25
Chris@210 26 @config = nil
Chris@210 27
Chris@210 28 class << self
Chris@210 29 # Loads the Redmine configuration file
Chris@210 30 # Valid options:
Chris@210 31 # * <tt>:file</tt>: the configuration file to load (default: config/configuration.yml)
Chris@210 32 # * <tt>:env</tt>: the environment to load the configuration for (default: Rails.env)
Chris@210 33 def load(options={})
Chris@210 34 filename = options[:file] || File.join(Rails.root, 'config', 'configuration.yml')
Chris@210 35 env = options[:env] || Rails.env
Chris@210 36
Chris@210 37 @config = @defaults.dup
Chris@210 38
Chris@210 39 load_deprecated_email_configuration(env)
Chris@210 40 if File.file?(filename)
Chris@210 41 @config.merge!(load_from_yaml(filename, env))
Chris@210 42 end
Chris@210 43
Chris@210 44 # Compatibility mode for those who copy email.yml over configuration.yml
Chris@210 45 %w(delivery_method smtp_settings sendmail_settings).each do |key|
Chris@210 46 if value = @config.delete(key)
Chris@210 47 @config['email_delivery'] ||= {}
Chris@210 48 @config['email_delivery'][key] = value
Chris@210 49 end
Chris@210 50 end
Chris@210 51
Chris@210 52 if @config['email_delivery']
Chris@210 53 ActionMailer::Base.perform_deliveries = true
Chris@210 54 @config['email_delivery'].each do |k, v|
Chris@210 55 v.symbolize_keys! if v.respond_to?(:symbolize_keys!)
Chris@210 56 ActionMailer::Base.send("#{k}=", v)
Chris@210 57 end
Chris@210 58 end
Chris@210 59
Chris@210 60 @config
Chris@210 61 end
Chris@210 62
Chris@210 63 # Returns a configuration setting
Chris@210 64 def [](name)
Chris@210 65 load unless @config
Chris@210 66 @config[name]
Chris@210 67 end
Chris@210 68
Chris@210 69 private
Chris@210 70
Chris@210 71 def load_from_yaml(filename, env)
Chris@210 72 yaml = YAML::load_file(filename)
Chris@210 73 conf = {}
Chris@210 74 if yaml.is_a?(Hash)
Chris@210 75 if yaml['default']
Chris@210 76 conf.merge!(yaml['default'])
Chris@210 77 end
Chris@210 78 if yaml[env]
Chris@210 79 conf.merge!(yaml[env])
Chris@210 80 end
Chris@210 81 else
Chris@210 82 $stderr.puts "#{filename} is not a valid Redmine configuration file"
Chris@210 83 exit 1
Chris@210 84 end
Chris@210 85 conf
Chris@210 86 end
Chris@210 87
Chris@210 88 def load_deprecated_email_configuration(env)
Chris@210 89 deprecated_email_conf = File.join(Rails.root, 'config', 'email.yml')
Chris@210 90 if File.file?(deprecated_email_conf)
Chris@210 91 warn "Storing outgoing emails configuration in config/email.yml is deprecated. You should now store it in config/configuration.yml using the email_delivery setting."
Chris@210 92 @config.merge!({'email_delivery' => load_from_yaml(deprecated_email_conf, env)})
Chris@210 93 end
Chris@210 94 end
Chris@210 95 end
Chris@210 96 end
Chris@210 97 end