Skip to content
Browse files

Default values now use a constant rather than a class variable.

git-svn-id: http://beautifulpixel.com/svn/plugins/settings@10 3ad9c75a-930d-0410-97f1-af11573dca1c
  • Loading branch information...
1 parent d61bc29 commit b2b7d545b5bd5f83eb539fef6727cc994ffe0098 squeegy committed
Showing with 5 additions and 16 deletions.
  1. +1 −3 README
  2. +3 −12 lib/settings.rb
  3. +1 −1 test/settings_test.rb
View
4 README
@@ -25,9 +25,7 @@ Want a list of all the settings?
Set defaults for certain settings of your app. This will cause the defined settings to return with the
Specified value even if they are not in the database.
- Settings.default_values = {:some_setting => 'foo'}
- or
- Settings.default_values.merge!({:some_setting => 'foo'}) #put a line like this in environment.rb
+ Settings::DEFAULT_VALUES.merge!({:some_setting => 'foo'}) #put a line like this in environment.rb
Settings.some_setting #=> returns "foo" even though no record is in the databse for "some_setting"
Settings.some_setting = 'bar' # Database record is now created and this record will be used instead of the default
View
15 lib/settings.rb
@@ -1,16 +1,7 @@
class Settings < ActiveRecord::Base
- @@defaults = {}.with_indifferent_access
@@cache = {}.with_indifferent_access
- #returns the default values hash
- def self.default_values
- @@defaults
- end
-
- #sets the default values hash
- def self.default_values=(hash)
- @@defaults = hash.with_indifferent_access
- end
+ DEFAULT_VALUES = {}.with_indifferent_access
#get or set a variable with the variable as the called method
def self.method_missing(method, *args)
@@ -61,8 +52,8 @@ def self.[](var_name)
if var = find(:first, :conditions => ['var = ?', var_name])
@@cache[var_name] = var.value
var.value
- elsif @@defaults[var_name]
- @@defaults[var_name]
+ elsif DEFAULT_VALUES[var_name]
+ DEFAULT_VALUES[var_name]
else
nil
end
View
2 test/settings_test.rb
@@ -9,7 +9,7 @@ def setup
end
def test_defaults
- Settings.default_values.merge!({:some_setting => 'foo'})
+ Settings::DEFAULT_VALUES.merge!({:some_setting => 'foo'})
assert_equal 'foo', Settings.some_setting
assert_nil Settings.find(:first, :conditions => ['var = ?', 'some_setting'])

0 comments on commit b2b7d54

Please sign in to comment.
Something went wrong with that request. Please try again.