diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-01-21 11:50:22 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-01-21 11:50:22 +0000 |
commit | 0b4d4db131304eac84dc90b289a95db3410a2bfe (patch) | |
tree | b5ad6934b897635e594ca089f06fe953d082ed53 /app/models/setting.rb | |
parent | a1b12335ab6a01ea6e7dcc1df490db16136c8c2a (diff) | |
download | redmine-0b4d4db131304eac84dc90b289a95db3410a2bfe.tar.gz redmine-0b4d4db131304eac84dc90b289a95db3410a2bfe.zip |
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings
git-svn-id: http://redmine.rubyforge.org/svn/trunk@167 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/setting.rb')
-rw-r--r-- | app/models/setting.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/app/models/setting.rb b/app/models/setting.rb new file mode 100644 index 000000000..7350d9123 --- /dev/null +++ b/app/models/setting.rb @@ -0,0 +1,61 @@ +# redMine - project management software +# Copyright (C) 2006-2007 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. + +class Setting < ActiveRecord::Base + + cattr_accessor :available_settings + @@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml")) + + validates_uniqueness_of :name + validates_inclusion_of :name, :in => @@available_settings.keys + validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' } + + def self.get(name) + name = name.to_s + setting = find_by_name(name) + setting ||= new(:name => name, :value => @@available_settings[name]['default']) if @@available_settings.has_key? name + setting + end + + def self.[](name) + get(name).value + end + + def self.[]=(name, value) + setting = get(name) + setting.value = value + setting.save + setting.value + end + + @@available_settings.each do |name, params| + src = <<-END_SRC + def self.#{name} + self[:#{name}] + end + + def self.#{name}? + self[:#{name}].to_s == "1" + end + + def self.#{name}=(value) + self[:#{name}] = values + end + END_SRC + class_eval src, __FILE__, __LINE__ + end +end |