rails-settings-cached 0.3.2 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +27 -5
- data/lib/rails-settings/settings.rb +4 -3
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40794840901a71892c30090b1fd7b18c32a7f722
|
4
|
+
data.tar.gz: 6f673ba78ea6ac61cda0d006e2f582882e58c4d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f8b6d47cdcf304ef4fb587d9b2613f11583ccd398511cf91c52388bf03941f4db5e3abe3f5b7ebe469618a2075a85c57f3faac6eb7e27405eb7c7ee8cc24243
|
7
|
+
data.tar.gz: 78c71f7ef47f0784adc9149af44305af41fe71ca8a4a3abb065a87c8cc2a1445fc3f276b1632a58a6cbfcb0fbe15583bc9993e831d4f3eba00c8e868c67da086
|
data/README.md
CHANGED
@@ -17,6 +17,8 @@ arrays, or any object. Ported to Rails 3!
|
|
17
17
|
Edit your Gemfile:
|
18
18
|
|
19
19
|
```ruby
|
20
|
+
# Rails 4.1.x
|
21
|
+
gem "rails-settings-cached", "0.4.0"
|
20
22
|
# Rails 4+
|
21
23
|
gem "rails-settings-cached", "0.3.1"
|
22
24
|
# Rails 3.x
|
@@ -84,17 +86,17 @@ Setting.foo # returns nil
|
|
84
86
|
Want a list of all the settings?
|
85
87
|
|
86
88
|
```ruby
|
87
|
-
Setting.
|
89
|
+
Setting.get_all
|
88
90
|
# returns {'admin_password' => 'super_secret', 'date_format' => '%m %d, %Y'}
|
89
91
|
```
|
90
92
|
|
91
|
-
You need name spaces and want a list of settings for a give name space? Just choose your prefered named space delimiter and use Setting.
|
93
|
+
You need name spaces and want a list of settings for a give name space? Just choose your prefered named space delimiter and use Setting.get_all like this:
|
92
94
|
|
93
95
|
```ruby
|
94
96
|
Setting['preferences.color'] = :blue
|
95
97
|
Setting['preferences.size'] = :large
|
96
98
|
Setting['license.key'] = 'ABC-DEF'
|
97
|
-
Setting.
|
99
|
+
Setting.get_all('preferences.')
|
98
100
|
# returns { 'preferences.color' => :blue, 'preferences.size' => :large }
|
99
101
|
```
|
100
102
|
|
@@ -135,7 +137,7 @@ Then you can set/get a setting for a given user instance just by doing this:
|
|
135
137
|
user = User.find(123)
|
136
138
|
user.settings.color = :red
|
137
139
|
user.settings.color # returns :red
|
138
|
-
user.settings.
|
140
|
+
user.settings.get_all # { "color" => :red }
|
139
141
|
```
|
140
142
|
|
141
143
|
I you want to find users having or not having some settings, there are named scopes for this:
|
@@ -148,10 +150,30 @@ User.with_settings_for('color')
|
|
148
150
|
# => returns a scope of users having a 'color' setting
|
149
151
|
|
150
152
|
User.without_settings
|
151
|
-
# returns a scope of users having no setting at all (means user.settings.
|
153
|
+
# returns a scope of users having no setting at all (means user.settings.get_all == {})
|
152
154
|
|
153
155
|
User.without_settings('color')
|
154
156
|
# returns a scope of users having no 'color' setting (means user.settings.color == nil)
|
155
157
|
```
|
156
158
|
|
159
|
+
-----
|
160
|
+
|
161
|
+
## How to create a list, form to manage Settings?
|
162
|
+
|
163
|
+
If you want create an admin interface to editing the Settings, you can try methods in follow:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
class SettingsController < ApplicationController
|
167
|
+
def index
|
168
|
+
# to get all items for render list
|
169
|
+
@settings = Setting.unscoped
|
170
|
+
end
|
171
|
+
|
172
|
+
def edit
|
173
|
+
@setting = Setting.unscoped.find(params[:id])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
178
|
+
|
157
179
|
That's all there is to it! Enjoy!
|
@@ -32,8 +32,9 @@ module RailsSettings
|
|
32
32
|
#destroy the specified settings record
|
33
33
|
def self.destroy(var_name)
|
34
34
|
var_name = var_name.to_s
|
35
|
-
|
36
|
-
|
35
|
+
obj = object(var_name)
|
36
|
+
unless obj.nil?
|
37
|
+
obj.destroy
|
37
38
|
true
|
38
39
|
else
|
39
40
|
raise SettingNotFound, "Setting variable \"#{var_name}\" not found"
|
@@ -41,7 +42,7 @@ module RailsSettings
|
|
41
42
|
end
|
42
43
|
|
43
44
|
#retrieve all settings as a hash (optionally starting with a given namespace)
|
44
|
-
def self.
|
45
|
+
def self.get_all(starting_with = nil)
|
45
46
|
vars = thing_scoped.select("var,value")
|
46
47
|
if starting_with
|
47
48
|
vars = vars.where("var LIKE '#{starting_with}%'")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-settings-cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Squeegy
|
@@ -11,20 +11,20 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 4.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 4.0.0
|
30
30
|
description:
|
@@ -33,15 +33,15 @@ executables: []
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
+
- README.md
|
36
37
|
- lib/generators/settings/settings_generator.rb
|
37
38
|
- lib/generators/settings/templates/migration.rb
|
38
39
|
- lib/generators/settings/templates/model.rb
|
40
|
+
- lib/rails-settings-cached.rb
|
39
41
|
- lib/rails-settings/cached_settings.rb
|
40
42
|
- lib/rails-settings/extend.rb
|
41
43
|
- lib/rails-settings/scoped_settings.rb
|
42
44
|
- lib/rails-settings/settings.rb
|
43
|
-
- lib/rails-settings-cached.rb
|
44
|
-
- README.md
|
45
45
|
homepage: https://github.com/huacnlee/rails-settings-cached
|
46
46
|
licenses: []
|
47
47
|
metadata: {}
|
@@ -51,17 +51,17 @@ require_paths:
|
|
51
51
|
- lib
|
52
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
63
|
rubyforge_project:
|
64
|
-
rubygems_version: 2.
|
64
|
+
rubygems_version: 2.2.2
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: This is imporved from rails-settings, added caching. Settings is a plugin
|
@@ -71,4 +71,3 @@ summary: This is imporved from rails-settings, added caching. Settings is a plug
|
|
71
71
|
into your rails app. You can store any kind of object. Strings, numbers, arrays,
|
72
72
|
or any object. Ported to Rails 3!
|
73
73
|
test_files: []
|
74
|
-
has_rdoc:
|