summaryrefslogtreecommitdiffstats
path: root/lib/redmine/configuration.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-01-23 10:22:00 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-01-23 10:22:00 +0000
commit4cefae0aaadfadae71d695b17468fca2dfe74541 (patch)
treeaeceb744a0d9c38c17f0408d953baf614497bf6a /lib/redmine/configuration.rb
parente173f7e72dff82dfe55656a0ea0b7cf25f0c45de (diff)
downloadredmine-4cefae0aaadfadae71d695b17468fca2dfe74541.tar.gz
redmine-4cefae0aaadfadae71d695b17468fca2dfe74541.zip
Adds an application configuration file: config/configuration.yml (#7408).
Email delivery settings that were stored in config/email.yml should be moved to this new configuration file. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4752 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/configuration.rb')
-rw-r--r--lib/redmine/configuration.rb97
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/redmine/configuration.rb b/lib/redmine/configuration.rb
new file mode 100644
index 000000000..1d2443a9c
--- /dev/null
+++ b/lib/redmine/configuration.rb
@@ -0,0 +1,97 @@
+# Redmine - project management software
+# Copyright (C) 2006-2011 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+module Redmine
+ module Configuration
+
+ # Configuration default values
+ @defaults = {
+ 'email_delivery' => nil
+ }
+
+ @config = nil
+
+ class << self
+ # Loads the Redmine configuration file
+ # Valid options:
+ # * <tt>:file</tt>: the configuration file to load (default: config/configuration.yml)
+ # * <tt>:env</tt>: the environment to load the configuration for (default: Rails.env)
+ def load(options={})
+ filename = options[:file] || File.join(Rails.root, 'config', 'configuration.yml')
+ env = options[:env] || Rails.env
+
+ @config = @defaults.dup
+
+ load_deprecated_email_configuration(env)
+ if File.file?(filename)
+ @config.merge!(load_from_yaml(filename, env))
+ end
+
+ # Compatibility mode for those who copy email.yml over configuration.yml
+ %w(delivery_method smtp_settings sendmail_settings).each do |key|
+ if value = @config.delete(key)
+ @config['email_delivery'] ||= {}
+ @config['email_delivery'][key] = value
+ end
+ end
+
+ if @config['email_delivery']
+ ActionMailer::Base.perform_deliveries = true
+ @config['email_delivery'].each do |k, v|
+ v.symbolize_keys! if v.respond_to?(:symbolize_keys!)
+ ActionMailer::Base.send("#{k}=", v)
+ end
+ end
+
+ @config
+ end
+
+ # Returns a configuration setting
+ def [](name)
+ load unless @config
+ @config[name]
+ end
+
+ private
+
+ def load_from_yaml(filename, env)
+ yaml = YAML::load_file(filename)
+ conf = {}
+ if yaml.is_a?(Hash)
+ if yaml['default']
+ conf.merge!(yaml['default'])
+ end
+ if yaml[env]
+ conf.merge!(yaml[env])
+ end
+ else
+ $stderr.puts "#{filename} is not a valid Redmine configuration file"
+ exit 1
+ end
+ conf
+ end
+
+ def load_deprecated_email_configuration(env)
+ deprecated_email_conf = File.join(Rails.root, 'config', 'email.yml')
+ if File.file?(deprecated_email_conf)
+ 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."
+ @config.merge!({'email_delivery' => load_from_yaml(deprecated_email_conf, env)})
+ end
+ end
+ end
+ end
+end