annotate .svn/pristine/f9/f924ef380c43b9bc6870c2880f294487b8ad3aa8.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 module Redmine
Chris@1295 19 module Configuration
Chris@1295 20
Chris@1295 21 # Configuration default values
Chris@1295 22 @defaults = {
Chris@1295 23 'email_delivery' => nil
Chris@1295 24 }
Chris@1295 25
Chris@1295 26 @config = nil
Chris@1295 27
Chris@1295 28 class << self
Chris@1295 29 # Loads the Redmine configuration file
Chris@1295 30 # Valid options:
Chris@1295 31 # * <tt>:file</tt>: the configuration file to load (default: config/configuration.yml)
Chris@1295 32 # * <tt>:env</tt>: the environment to load the configuration for (default: Rails.env)
Chris@1295 33 def load(options={})
Chris@1295 34 filename = options[:file] || File.join(Rails.root, 'config', 'configuration.yml')
Chris@1295 35 env = options[:env] || Rails.env
Chris@1295 36
Chris@1295 37 @config = @defaults.dup
Chris@1295 38
Chris@1295 39 load_deprecated_email_configuration(env)
Chris@1295 40 if File.file?(filename)
Chris@1295 41 @config.merge!(load_from_yaml(filename, env))
Chris@1295 42 end
Chris@1295 43
Chris@1295 44 # Compatibility mode for those who copy email.yml over configuration.yml
Chris@1295 45 %w(delivery_method smtp_settings sendmail_settings).each do |key|
Chris@1295 46 if value = @config.delete(key)
Chris@1295 47 @config['email_delivery'] ||= {}
Chris@1295 48 @config['email_delivery'][key] = value
Chris@1295 49 end
Chris@1295 50 end
Chris@1295 51
Chris@1295 52 if @config['email_delivery']
Chris@1295 53 ActionMailer::Base.perform_deliveries = true
Chris@1295 54 @config['email_delivery'].each do |k, v|
Chris@1295 55 v.symbolize_keys! if v.respond_to?(:symbolize_keys!)
Chris@1295 56 ActionMailer::Base.send("#{k}=", v)
Chris@1295 57 end
Chris@1295 58 end
Chris@1295 59
Chris@1295 60 @config
Chris@1295 61 end
Chris@1295 62
Chris@1295 63 # Returns a configuration setting
Chris@1295 64 def [](name)
Chris@1295 65 load unless @config
Chris@1295 66 @config[name]
Chris@1295 67 end
Chris@1295 68
Chris@1295 69 # Yields a block with the specified hash configuration settings
Chris@1295 70 def with(settings)
Chris@1295 71 settings.stringify_keys!
Chris@1295 72 load unless @config
Chris@1295 73 was = settings.keys.inject({}) {|h,v| h[v] = @config[v]; h}
Chris@1295 74 @config.merge! settings
Chris@1295 75 yield if block_given?
Chris@1295 76 @config.merge! was
Chris@1295 77 end
Chris@1295 78
Chris@1295 79 private
Chris@1295 80
Chris@1295 81 def load_from_yaml(filename, env)
Chris@1295 82 yaml = nil
Chris@1295 83 begin
Chris@1295 84 yaml = YAML::load_file(filename)
Chris@1295 85 rescue ArgumentError
Chris@1295 86 $stderr.puts "Your Redmine configuration file located at #{filename} is not a valid YAML file and could not be loaded."
Chris@1295 87 exit 1
Chris@1295 88 end
Chris@1295 89 conf = {}
Chris@1295 90 if yaml.is_a?(Hash)
Chris@1295 91 if yaml['default']
Chris@1295 92 conf.merge!(yaml['default'])
Chris@1295 93 end
Chris@1295 94 if yaml[env]
Chris@1295 95 conf.merge!(yaml[env])
Chris@1295 96 end
Chris@1295 97 else
Chris@1295 98 $stderr.puts "Your Redmine configuration file located at #{filename} is not a valid Redmine configuration file."
Chris@1295 99 exit 1
Chris@1295 100 end
Chris@1295 101 conf
Chris@1295 102 end
Chris@1295 103
Chris@1295 104 def load_deprecated_email_configuration(env)
Chris@1295 105 deprecated_email_conf = File.join(Rails.root, 'config', 'email.yml')
Chris@1295 106 if File.file?(deprecated_email_conf)
Chris@1295 107 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@1295 108 @config.merge!({'email_delivery' => load_from_yaml(deprecated_email_conf, env)})
Chris@1295 109 end
Chris@1295 110 end
Chris@1295 111 end
Chris@1295 112 end
Chris@1295 113 end