To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / lib / redmine / configuration.rb @ 912:5e80956cc792
History | View | Annotate | Download (3.73 KB)
| 1 | 210:0579821a129a | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 210:0579821a129a | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 210:0579821a129a | Chris | # 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 | 909:cbb26bc654de | Chris | |
| 21 | 210:0579821a129a | Chris | # Configuration default values
|
| 22 | @defaults = {
|
||
| 23 | 'email_delivery' => nil |
||
| 24 | } |
||
| 25 | 909:cbb26bc654de | Chris | |
| 26 | 210:0579821a129a | Chris | @config = nil |
| 27 | 909:cbb26bc654de | Chris | |
| 28 | 210:0579821a129a | Chris | class << self |
| 29 | # Loads the Redmine configuration file
|
||
| 30 | # Valid options:
|
||
| 31 | # * <tt>:file</tt>: the configuration file to load (default: config/configuration.yml)
|
||
| 32 | 909:cbb26bc654de | Chris | # * <tt>:env</tt>: the environment to load the configuration for (default: Rails.env)
|
| 33 | 210:0579821a129a | Chris | def load(options={}) |
| 34 | filename = options[:file] || File.join(Rails.root, 'config', 'configuration.yml') |
||
| 35 | env = options[:env] || Rails.env |
||
| 36 | 909:cbb26bc654de | Chris | |
| 37 | 210:0579821a129a | Chris | @config = @defaults.dup |
| 38 | 909:cbb26bc654de | Chris | |
| 39 | 210:0579821a129a | Chris | load_deprecated_email_configuration(env) |
| 40 | if File.file?(filename) |
||
| 41 | @config.merge!(load_from_yaml(filename, env))
|
||
| 42 | end
|
||
| 43 | 909:cbb26bc654de | Chris | |
| 44 | 210:0579821a129a | Chris | # Compatibility mode for those who copy email.yml over configuration.yml
|
| 45 | %w(delivery_method smtp_settings sendmail_settings).each do |key| |
||
| 46 | if value = @config.delete(key) |
||
| 47 | @config['email_delivery'] ||= {} |
||
| 48 | @config['email_delivery'][key] = value |
||
| 49 | end
|
||
| 50 | end
|
||
| 51 | 909:cbb26bc654de | Chris | |
| 52 | 210:0579821a129a | Chris | if @config['email_delivery'] |
| 53 | ActionMailer::Base.perform_deliveries = true |
||
| 54 | @config['email_delivery'].each do |k, v| |
||
| 55 | v.symbolize_keys! if v.respond_to?(:symbolize_keys!) |
||
| 56 | ActionMailer::Base.send("#{k}=", v) |
||
| 57 | end
|
||
| 58 | end
|
||
| 59 | 909:cbb26bc654de | Chris | |
| 60 | 210:0579821a129a | Chris | @config
|
| 61 | end
|
||
| 62 | 909:cbb26bc654de | Chris | |
| 63 | 210:0579821a129a | Chris | # Returns a configuration setting
|
| 64 | def [](name) |
||
| 65 | load unless @config |
||
| 66 | @config[name]
|
||
| 67 | end
|
||
| 68 | 909:cbb26bc654de | Chris | |
| 69 | 245:051f544170fe | Chris | # Yields a block with the specified hash configuration settings
|
| 70 | def with(settings) |
||
| 71 | settings.stringify_keys! |
||
| 72 | load unless @config |
||
| 73 | was = settings.keys.inject({}) {|h,v| h[v] = @config[v]; h}
|
||
| 74 | @config.merge! settings
|
||
| 75 | yield if block_given? |
||
| 76 | @config.merge! was
|
||
| 77 | end
|
||
| 78 | 909:cbb26bc654de | Chris | |
| 79 | 210:0579821a129a | Chris | private |
| 80 | 909:cbb26bc654de | Chris | |
| 81 | 210:0579821a129a | Chris | def load_from_yaml(filename, env) |
| 82 | 909:cbb26bc654de | Chris | yaml = nil
|
| 83 | begin
|
||
| 84 | yaml = YAML::load_file(filename)
|
||
| 85 | rescue ArgumentError |
||
| 86 | $stderr.puts "Your Redmine configuration file located at #{filename} is not a valid YAML file and could not be loaded." |
||
| 87 | exit 1
|
||
| 88 | end
|
||
| 89 | 210:0579821a129a | Chris | conf = {}
|
| 90 | if yaml.is_a?(Hash) |
||
| 91 | if yaml['default'] |
||
| 92 | conf.merge!(yaml['default'])
|
||
| 93 | end
|
||
| 94 | if yaml[env]
|
||
| 95 | conf.merge!(yaml[env]) |
||
| 96 | end
|
||
| 97 | else
|
||
| 98 | 909:cbb26bc654de | Chris | $stderr.puts "Your Redmine configuration file located at #{filename} is not a valid Redmine configuration file." |
| 99 | 210:0579821a129a | Chris | exit 1
|
| 100 | end
|
||
| 101 | conf |
||
| 102 | end
|
||
| 103 | 909:cbb26bc654de | Chris | |
| 104 | 210:0579821a129a | Chris | def load_deprecated_email_configuration(env) |
| 105 | deprecated_email_conf = File.join(Rails.root, 'config', 'email.yml') |
||
| 106 | if File.file?(deprecated_email_conf) |
||
| 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."
|
||
| 108 | @config.merge!({'email_delivery' => load_from_yaml(deprecated_email_conf, env)}) |
||
| 109 | end
|
||
| 110 | end
|
||
| 111 | end
|
||
| 112 | end
|
||
| 113 | end |