Class: Setting
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Setting
- Defined in:
- app/models/setting.rb
Overview
– copyright ChiliProject is a project management system.
Copyright (C) 2010-2013 the ChiliProject Team
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.
See doc/COPYRIGHT.rdoc for more details. ++
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 CP932 GB18030 GBK ISCII91 EUC-KR Big5 Big5-HKSCS TIS-620)
- @@available_settings =
YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
Class Method Summary (collapse)
-
+ (Object) [](name)
Returns the value of the setting named name.
- + (Object) []=(name, v)
-
+ (Object) check_cache
Deprecation Warning: This method is no longer available.
-
+ (Object) clear_cache
Clears all of the Setting caches.
- + (Boolean) openid?
-
+ (Object) per_page_options_array
Helper that returns an array based on per_page_options setting.
-
+ (Object) uncached
Temporarily deactivate settings caching in the block scope.
-
+ (Object) use_caching=(new_value)
Dis-/En-able Setting caching.
-
+ (Boolean) use_caching?
Check if Setting caching should be performed.
Instance Method Summary (collapse)
Class Method Details
+ (Object) [](name)
Returns the value of the setting named name
99 100 101 102 103 104 105 |
# File 'app/models/setting.rb', line 99 def self.[](name) if use_caching? Marshal.load(Rails.cache.fetch(self.cache_key(name)) {Marshal.dump(find_or_default(name).value)}) else find_or_default(name).value end end |
+ (Object) []=(name, v)
107 108 109 110 111 112 113 |
# File 'app/models/setting.rb', line 107 def self.[]=(name, v) setting = find_or_default(name) setting.value = (v ? v : "") Rails.cache.delete self.cache_key(name) setting.save setting.value end |
+ (Object) check_cache
Deprecation Warning: This method is no longer available. There is no replacement.
146 147 148 149 150 151 |
# File 'app/models/setting.rb', line 146 def self.check_cache # DEPRECATED SINCE 3.0.0beta2 ActiveSupport::Deprecation.warn "The Setting.check_cache method is " + "deprecated and will be removed in the future. There should be no " + "replacement for this functionality needed." end |
+ (Object) clear_cache
Clears all of the Setting caches
154 155 156 157 158 159 160 161 |
# File 'app/models/setting.rb', line 154 def self.clear_cache # DEPRECATED SINCE 3.0.0beta2 ActiveSupport::Deprecation.warn "The Setting.clear_cache method is " + "deprecated and will be removed in the future. There should be no " + "replacement for this functionality needed. To sweep the whole " + "cache Rails.cache.clear may be used. To invalidate the Settings " + "only, you may use Setting.first.try(:touch)" end |
+ (Boolean) openid?
140 141 142 |
# File 'app/models/setting.rb', line 140 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
136 137 138 |
# File 'app/models/setting.rb', line 136 def self. .split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort end |
+ (Object) uncached
Temporarily deactivate settings caching in the block scope
164 165 166 167 168 169 170 |
# File 'app/models/setting.rb', line 164 def self.uncached cache_setting = self.use_caching self.use_caching = false yield ensure self.use_caching = cache_setting end |
+ (Object) use_caching=(new_value)
Dis-/En-able Setting caching. This is mainly intended to be used in tests
178 179 180 |
# File 'app/models/setting.rb', line 178 def self.use_caching=(new_value) Thread.current['chiliproject/settings/do_not_use_caching'] = !new_value end |
+ (Boolean) use_caching?
Check if Setting caching should be performed
173 174 175 |
# File 'app/models/setting.rb', line 173 def self.use_caching? !Thread.current['chiliproject/settings/do_not_use_caching'] end |
Instance Method Details
- (Object) value
85 86 87 88 89 90 91 |
# File 'app/models/setting.rb', line 85 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)
93 94 95 96 |
# File 'app/models/setting.rb', line 93 def value=(v) v = v.to_yaml if v && @@available_settings[name] && @@available_settings[name]['serialized'] write_attribute(:value, v.to_s) end |