rails-settings-cached 2.3.5 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -12
- data/lib/rails-settings-cached.rb +1 -0
- data/lib/rails-settings/base.rb +2 -4
- data/lib/rails-settings/request_store.rb +8 -0
- data/lib/rails-settings/version.rb +1 -1
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 603b7101883a17d76bfb33682ce421b7259101bfc7d3b0fea450d02466adcb03
|
4
|
+
data.tar.gz: '088348b905fba8727569b052468ca194c74fcde740976e0d4cfe6b780063144f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeaed942036ec6c70fbd0f8a687000032e87cbef17324eca6329c32e1f7b69b6f38a7d295ec00441ec1fd1601f53c8cbe162df33e0f5d4f518658f6cb3236835
|
7
|
+
data.tar.gz: 13f87d6cac9234fcf48b50b3e67723aac4977d4a9e8fb71528bf8d12fd29eb27372d9b5705a496f694550ad988dba613f9dc3bf069fa699a910ebd1f4c5b8506
|
data/README.md
CHANGED
@@ -126,7 +126,6 @@ irb > Setting.notification_options
|
|
126
126
|
}
|
127
127
|
```
|
128
128
|
|
129
|
-
|
130
129
|
### Get defined fields
|
131
130
|
|
132
131
|
> version 2.3+
|
@@ -151,7 +150,7 @@ Setting.get_field("app_name")
|
|
151
150
|
=> { key: "app_name", type: :string, default: "Rails Settings", readonly: false }
|
152
151
|
```
|
153
152
|
|
154
|
-
## Use Setting in Rails
|
153
|
+
## Use Setting in Rails initializing:
|
155
154
|
|
156
155
|
In `version 2.3+` we allows you to use Setting before Rails is initialized.
|
157
156
|
|
@@ -174,10 +173,9 @@ end
|
|
174
173
|
|
175
174
|
## Readonly field
|
176
175
|
|
177
|
-
You may also want use Setting
|
176
|
+
You may also want use Setting before Rails initialize:
|
178
177
|
|
179
178
|
```
|
180
|
-
config/application.rb
|
181
179
|
config/environments/*.rb
|
182
180
|
```
|
183
181
|
|
@@ -200,14 +198,19 @@ class Setting < RailsSettings::Base
|
|
200
198
|
end
|
201
199
|
```
|
202
200
|
|
201
|
+
config/environments/production.rb
|
202
|
+
|
203
203
|
```rb
|
204
|
+
# You must require_relative directly in Rails 6.1+ in config/environments/production.rb
|
205
|
+
require_relative "../../app/models/setting"
|
206
|
+
|
204
207
|
Rails.application.configure do
|
205
208
|
config.action_mailer.delivery_method = :smtp
|
206
209
|
config.action_mailer.smtp_settings = Setting.mailer_options.deep_symbolize_keys
|
207
210
|
end
|
208
211
|
```
|
209
212
|
|
210
|
-
|
213
|
+
## Caching flow:
|
211
214
|
|
212
215
|
```
|
213
216
|
Setting.host -> Check Cache -> Exist - Get value of key for cache -> Return
|
@@ -217,7 +220,7 @@ Setting.host -> Check Cache -> Exist - Get value of key for cache -> Return
|
|
217
220
|
Return default value or nil
|
218
221
|
```
|
219
222
|
|
220
|
-
In each Setting keys call, we will load the cache/db and save in [
|
223
|
+
In each Setting keys call, we will load the cache/db and save in [ActiveSupport::CurrentAttributes](https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html) to avoid hit cache/db.
|
221
224
|
|
222
225
|
Each key update will expire the cache, so do not add some frequent update key.
|
223
226
|
|
@@ -242,7 +245,7 @@ class ActiveSupport::TestCase
|
|
242
245
|
end
|
243
246
|
```
|
244
247
|
|
245
|
-
|
248
|
+
---
|
246
249
|
|
247
250
|
## How to manage Settings in the admin interface?
|
248
251
|
|
@@ -256,19 +259,16 @@ namespace :admin do
|
|
256
259
|
end
|
257
260
|
```
|
258
261
|
|
259
|
-
|
260
262
|
app/controllers/admin/settings_controller.rb
|
261
263
|
|
262
264
|
```rb
|
263
265
|
module Admin
|
264
266
|
class SettingsController < ApplicationController
|
265
|
-
before_action :get_setting, only: [:edit, :update]
|
266
|
-
|
267
267
|
def create
|
268
268
|
setting_params.keys.each do |key|
|
269
269
|
Setting.send("#{key}=", setting_params[key].strip) unless setting_params[key].nil?
|
270
270
|
end
|
271
|
-
redirect_to
|
271
|
+
redirect_to admin_settings_path, notice: "Setting was successfully updated."
|
272
272
|
end
|
273
273
|
|
274
274
|
private
|
@@ -353,5 +353,4 @@ end
|
|
353
353
|
- [tootsuite/mastodon](https://github.com/tootsuite/mastodon) - 0.6.x
|
354
354
|
- [helpyio/helpy](https://github.com/helpyio/helpy) - 0.5.x
|
355
355
|
|
356
|
-
|
357
356
|
And more than [1K repositories](https://github.com/huacnlee/rails-settings-cached/network/dependents) used.
|
data/lib/rails-settings/base.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "request_store"
|
4
|
-
|
5
3
|
module RailsSettings
|
6
4
|
class Base < ActiveRecord::Base
|
7
5
|
class SettingNotFound < RuntimeError; end
|
@@ -25,7 +23,7 @@ module RailsSettings
|
|
25
23
|
|
26
24
|
class << self
|
27
25
|
def clear_cache
|
28
|
-
RequestStore.
|
26
|
+
RequestStore.reset
|
29
27
|
Rails.cache.delete(cache_key)
|
30
28
|
end
|
31
29
|
|
@@ -162,7 +160,7 @@ module RailsSettings
|
|
162
160
|
end
|
163
161
|
|
164
162
|
def _all_settings
|
165
|
-
RequestStore.
|
163
|
+
RequestStore.settings ||= begin
|
166
164
|
Rails.cache.fetch(cache_key, expires_in: 1.week) do
|
167
165
|
vars = unscoped.select("var, value")
|
168
166
|
result = {}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module RailsSettings
|
2
|
+
# For storage all settings in Current, it will reset after per request completed.
|
3
|
+
# Base on ActiveSupport::CurrentAttributes
|
4
|
+
# https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html
|
5
|
+
class RequestStore < ActiveSupport::CurrentAttributes
|
6
|
+
attribute :settings
|
7
|
+
end
|
8
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-settings-cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.2.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: request_store
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: codecov
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,6 +128,7 @@ files:
|
|
142
128
|
- lib/rails-settings-cached.rb
|
143
129
|
- lib/rails-settings/base.rb
|
144
130
|
- lib/rails-settings/railtie.rb
|
131
|
+
- lib/rails-settings/request_store.rb
|
145
132
|
- lib/rails-settings/version.rb
|
146
133
|
homepage: https://github.com/huacnlee/rails-settings-cached
|
147
134
|
licenses:
|
@@ -162,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
149
|
- !ruby/object:Gem::Version
|
163
150
|
version: '0'
|
164
151
|
requirements: []
|
165
|
-
rubygems_version: 3.
|
152
|
+
rubygems_version: 3.1.2
|
166
153
|
signing_key:
|
167
154
|
specification_version: 4
|
168
155
|
summary: Settings plugin for Rails that makes managing a table of global keys.
|