ruby-settings-cached 0.1 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/lib/ruby-settings/cached_settings.rb +4 -1
- data/lib/ruby-settings/configuration.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44b8a94e6e94cec323aba916059713daa49020e3
|
4
|
+
data.tar.gz: ad4402274c659dfc06c1bccf5f563cb98479e1f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3ff2bc6bf2e4fb9b93c683b71934ac3427de8d724a7d6b1b7735a2308eb2b83b9e1e8b980675ea1e5ea9b91335b5221647a099df6ab2142574c16a7df8e2def
|
7
|
+
data.tar.gz: 25f7a64b1181b9d7767684314d126e98eaaf385abb0b302e39f4942a98767e0a8c6cf64038aaaccbb4897a25a9ea7010ae4278632adadac43a20569169a53d56
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Settings Gem
|
2
2
|
|
3
|
-
This is improved from [rails-settings](https://github.com/
|
4
|
-
|
3
|
+
This is improved from [rails-settings-cached](https://github.com/huacnlee/rails-settings-cached),
|
4
|
+
remove rails dependency. Settings is a plugin that makes managing a table of
|
5
5
|
global key, value pairs easy. Think of it like a global Hash stored in your database,
|
6
6
|
that uses simple ActiveRecord like methods for manipulation. Keep track of any global
|
7
7
|
setting that you dont want to hard code into your rails app. You can store any kind
|
@@ -9,7 +9,7 @@ of object. Strings, numbers, arrays, or any object.
|
|
9
9
|
|
10
10
|
## Status
|
11
11
|
|
12
|
-
- [](https://rubygems.org/gems/ruby-settings-cached)
|
13
13
|
- [](https://travis-ci.org/RobotJiang/ruby-settings-cached)
|
14
14
|
|
15
15
|
## Setup
|
@@ -35,6 +35,12 @@ Now just put that migration in the database with:
|
|
35
35
|
rake db:migrate
|
36
36
|
```
|
37
37
|
|
38
|
+
```config
|
39
|
+
RubySettings.configure do |config|
|
40
|
+
# or memcached store, redis store, if you are using rails, the cache store is Rails.cache default, you need not to config it.
|
41
|
+
config.cache_store = ActiveSupport::Cache::MemoryStore.new
|
42
|
+
end
|
43
|
+
```
|
38
44
|
## Usage
|
39
45
|
|
40
46
|
The syntax is easy. First, lets create some settings to keep track of:
|
@@ -19,6 +19,9 @@ module RubySettings
|
|
19
19
|
end
|
20
20
|
|
21
21
|
class << self
|
22
|
+
|
23
|
+
include RubySettings::ConfigurationHelpers
|
24
|
+
|
22
25
|
def cache_prefix(&block)
|
23
26
|
@cache_prefix = block
|
24
27
|
end
|
@@ -31,7 +34,7 @@ module RubySettings
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def [](var_name)
|
34
|
-
value =
|
37
|
+
value = cache_store.fetch(cache_key(var_name, @object)) do
|
35
38
|
super(var_name)
|
36
39
|
end
|
37
40
|
|
@@ -22,7 +22,7 @@ module RubySettings
|
|
22
22
|
extend ActiveSupport::Concern
|
23
23
|
|
24
24
|
def cache_store
|
25
|
-
@cache_store ||= (RubySettings.config.cache_store || ActiveSupport::Cache::MemoryStore.new)
|
25
|
+
@cache_store ||= (RubySettings.config.cache_store || (defined?(Rails) ? Rails.cache : ActiveSupport::Cache::MemoryStore.new))
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|