settings-goo 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -6
- data/VERSION +1 -1
- data/lib/settings.rb +12 -1
- data/settings-goo.gemspec +2 -2
- data/test/test_settings.rb +68 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -42,9 +42,4 @@ Remove a setting:
|
|
42
42
|
Settings[:admin_email] # returns nil
|
43
43
|
|
44
44
|
List all setting keys:
|
45
|
-
Settings.keys # returns [:admin_email, :ca_tax, :per_page, :role_enabled]
|
46
|
-
|
47
|
-
== TODO
|
48
|
-
|
49
|
-
Cache Settings.keys
|
50
|
-
Cache Create rails plugin gem
|
45
|
+
Settings.keys # returns [:admin_email, :ca_tax, :per_page, :role_enabled]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/settings.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
class Settings < ActiveRecord::Base
|
2
|
+
validates_presence_of :key
|
2
3
|
validates_uniqueness_of :key
|
3
4
|
after_save :clear_cache
|
5
|
+
after_create :clear_cache_keys
|
6
|
+
#TODO - Only clear cached keys when :key is updated, not :value
|
7
|
+
after_update :clear_cache_keys
|
4
8
|
after_destroy :clear_cache
|
9
|
+
after_destroy :clear_cache_keys
|
5
10
|
|
6
11
|
def value
|
7
12
|
val = self[:value]
|
@@ -32,7 +37,9 @@ class Settings < ActiveRecord::Base
|
|
32
37
|
end
|
33
38
|
|
34
39
|
def self.keys
|
35
|
-
|
40
|
+
Rails.cache.fetch("settings/settings.keys") {
|
41
|
+
self.find(:all, :select => 'key', :order => 'key ASC').map{|s| s.key.to_sym}
|
42
|
+
}
|
36
43
|
end
|
37
44
|
|
38
45
|
def self.remove(key)
|
@@ -53,4 +60,8 @@ private
|
|
53
60
|
def clear_cache
|
54
61
|
Rails.cache.delete("settings/#{key}")
|
55
62
|
end
|
63
|
+
|
64
|
+
def clear_cache_keys
|
65
|
+
Rails.cache.delete("settings/settings.keys")
|
66
|
+
end
|
56
67
|
end
|
data/settings-goo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{settings-goo}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chris Kilmer"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-19}
|
13
13
|
s.description = %q{A simple ActiveRecord based model for storing global application settings for your rails application in your database.}
|
14
14
|
s.email = %q{chris.kilmer@dogwalkercentral.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_settings.rb
CHANGED
@@ -7,6 +7,14 @@ class SettingsTest < ActiveSupport::TestCase
|
|
7
7
|
Rails.cache.clear
|
8
8
|
end
|
9
9
|
|
10
|
+
##############################
|
11
|
+
# Validations #
|
12
|
+
##############################
|
13
|
+
test 'should require key' do
|
14
|
+
setting = Settings.create(:key => nil)
|
15
|
+
assert_not_nil setting.errors.on(:key)
|
16
|
+
end
|
17
|
+
|
10
18
|
##############################
|
11
19
|
# Proper Serialization #
|
12
20
|
##############################
|
@@ -64,6 +72,13 @@ class SettingsTest < ActiveSupport::TestCase
|
|
64
72
|
assert_equal setting, val
|
65
73
|
end
|
66
74
|
|
75
|
+
test 'should retrieve key immediatley after setting (when created with symbol)' do
|
76
|
+
key = :with_key
|
77
|
+
val = 'some val'
|
78
|
+
Settings[key] = val
|
79
|
+
assert_equal val, Settings[key]
|
80
|
+
end
|
81
|
+
|
67
82
|
test 'should set key' do
|
68
83
|
val = true
|
69
84
|
Settings[@key_name] = val
|
@@ -84,7 +99,13 @@ class SettingsTest < ActiveSupport::TestCase
|
|
84
99
|
test 'should return nil when trying to remove non-existent key' do
|
85
100
|
assert_nil Settings.remove :non_existent_key
|
86
101
|
end
|
87
|
-
|
102
|
+
|
103
|
+
test 'should not create setting with nil key' do
|
104
|
+
assert_no_difference('Settings.count') do
|
105
|
+
Settings[nil] = 'something'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
88
109
|
##############################
|
89
110
|
# Duplicate Handling #
|
90
111
|
##############################
|
@@ -147,4 +168,50 @@ class SettingsTest < ActiveSupport::TestCase
|
|
147
168
|
Settings.remove @key_name
|
148
169
|
assert_nil Rails.cache.fetch(cache_key)
|
149
170
|
end
|
171
|
+
|
172
|
+
test 'should create cache for Settings.keys' do
|
173
|
+
cache_key = "settings/settings.keys"
|
174
|
+
#Create a key
|
175
|
+
Settings[@key_name] = 'some val'
|
176
|
+
#Call to set cache
|
177
|
+
Settings.keys
|
178
|
+
assert_not_nil Rails.cache.fetch(cache_key)
|
179
|
+
end
|
180
|
+
|
181
|
+
test 'should remove cache for Settings.keys whenever a new key is added' do
|
182
|
+
cache_key = "settings/settings.keys"
|
183
|
+
#Create a key
|
184
|
+
Settings[@key_name] = 'some val'
|
185
|
+
#Call to set cache
|
186
|
+
Settings.keys
|
187
|
+
assert_not_nil Rails.cache.fetch(cache_key)
|
188
|
+
#Add a new key
|
189
|
+
Settings[:another_key] = 'some other val'
|
190
|
+
assert_nil Rails.cache.fetch(cache_key)
|
191
|
+
end
|
192
|
+
|
193
|
+
test 'should remove cache for Settings.keys whenever a key is updated' do
|
194
|
+
cache_key = "settings/settings.keys"
|
195
|
+
#Create a key
|
196
|
+
Settings[@key_name] = 'some val'
|
197
|
+
#Call to set cache
|
198
|
+
Settings.keys
|
199
|
+
assert_not_nil Rails.cache.fetch(cache_key)
|
200
|
+
#Update a key
|
201
|
+
setting = Settings.find_by_key(@key_name.to_s)
|
202
|
+
setting.update_attribute(:key, 'another_key')
|
203
|
+
assert_nil Rails.cache.fetch(cache_key)
|
204
|
+
end
|
205
|
+
|
206
|
+
test 'should remove cache for Settings.keys whenever a key is removed' do
|
207
|
+
cache_key = "settings/settings.keys"
|
208
|
+
#Create a key
|
209
|
+
Settings[@key_name] = 'some val'
|
210
|
+
#Call to set cache
|
211
|
+
Settings.keys
|
212
|
+
assert_not_nil Rails.cache.fetch(cache_key)
|
213
|
+
#Update a key
|
214
|
+
Settings.remove(@key_name)
|
215
|
+
assert_nil Rails.cache.fetch(cache_key)
|
216
|
+
end
|
150
217
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: settings-goo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Kilmer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|