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