Class: Setting
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Setting
- Defined in:
- app/models/setting.rb
Overview
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.
Constant Summary
- DATE_FORMATS =
[ '%Y-%m-%d', '%d/%m/%Y', '%d.%m.%Y', '%d-%m-%Y', '%m/%d/%Y', '%d %b %Y', '%d %B %Y', '%b %d, %Y', '%B %d, %Y' ]
- TIME_FORMATS =
[ '%H:%M', '%I:%M %p' ]
- ENCODINGS =
%w(US-ASCII windows-1250 windows-1251 windows-1252 windows-1253 windows-1254 windows-1255 windows-1256 windows-1257 windows-1258 windows-31j ISO-2022-JP ISO-2022-KR ISO-8859-1 ISO-8859-2 ISO-8859-3 ISO-8859-4 ISO-8859-5 ISO-8859-6 ISO-8859-7 ISO-8859-8 ISO-8859-9 ISO-8859-13 ISO-8859-15 KOI8-R UTF-8 UTF-16 UTF-16BE UTF-16LE EUC-JP Shift_JIS GB18030 GBK ISCII91 EUC-KR Big5 Big5-HKSCS TIS-620)
- @@available_settings =
YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
Class Method Summary
-
+ (Object) [](name)
Returns the value of the setting named name.
- + (Object) []=(name, v)
-
+ (Object) check_cache
Checks if settings have changed since the values were read and clears the cache hash if it’s the case Called once per request.
- + (Boolean) openid?
-
+ (Object) per_page_options_array
Helper that returns an array based on per_page_options setting.
Instance Method Summary
Methods inherited from ActiveRecord::Base
Class Method Details
+ (Object) [](name)
Returns the value of the setting named name
105 106 107 108 |
# File 'app/models/setting.rb', line 105 def self.[](name) v = @cached_settings[name] v ? v : (@cached_settings[name] = find_or_default(name).value) end |
+ (Object) []=(name, v)
110 111 112 113 114 115 116 |
# File 'app/models/setting.rb', line 110 def self.[]=(name, v) setting = find_or_default(name) setting.value = (v ? v : "") @cached_settings[name] = nil setting.save setting.value end |
+ (Object) check_cache
Checks if settings have changed since the values were read and clears the cache hash if it’s the case Called once per request
151 152 153 154 155 156 157 158 |
# File 'app/models/setting.rb', line 151 def self.check_cache settings_updated_on = Setting.maximum(:updated_on) if settings_updated_on && @cached_cleared_on <= settings_updated_on @cached_settings.clear @cached_cleared_on = Time.now logger.info "Settings cache cleared." if logger end end |
+ (Boolean) openid?
144 145 146 |
# File 'app/models/setting.rb', line 144 def self.openid? Object.const_defined?(:OpenID) && self[:openid].to_i > 0 end |
+ (Object) per_page_options_array
Helper that returns an array based on per_page_options setting
140 141 142 |
# File 'app/models/setting.rb', line 140 def self. .split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort end |
Instance Method Details
- (Object) value
91 92 93 94 95 96 97 |
# File 'app/models/setting.rb', line 91 def value v = read_attribute(:value) # Unserialize serialized settings v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String) v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank? v end |
- (Object) value=(v)
99 100 101 102 |
# File 'app/models/setting.rb', line 99 def value=(v) v = v.to_yaml if v && @@available_settings[name] && @@available_settings[name]['serialized'] write_attribute(:value, v.to_s) end |