rails-settings-cached 2.9.3 → 2.9.5
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 +13 -1
- data/lib/rails-settings/base.rb +8 -8
- data/lib/rails-settings/configuration.rb +23 -0
- data/lib/rails-settings/railtie.rb +0 -4
- data/lib/rails-settings/version.rb +1 -1
- data/lib/rails-settings-cached.rb +9 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc947f6d7c17fd74d160cedbbafe9b027a24fa4e56192ab4cf515f72ac3eb7b3
|
4
|
+
data.tar.gz: 2464010525a411701cad88349ff304ada0bf872b1cebdfff6627014ebfe971fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e8b7bdccafeffde0dbb610057b1dfd7c4b5b147663dea19880ad94b44186861efb1ec8b6321dc1aa0095938070522aa4bdf3d708db0eb1c74ec77505bbff8d0
|
7
|
+
data.tar.gz: 83dd5c6cf2faf96424b95dc9a6caaafb30c15f0eb05102eb7285b49cfc479423af3415cbdde3d6b6bb3f1342b437cd982b883572e9214eaa720267e83249fbdc
|
data/README.md
CHANGED
@@ -465,6 +465,18 @@ app/views/admin/settings/show.html.erb
|
|
465
465
|
<% end %>
|
466
466
|
```
|
467
467
|
|
468
|
+
## Special Cache Storage
|
469
|
+
|
470
|
+
You can use `cache_store` to change cache storage, default is `Rails.cache`.
|
471
|
+
|
472
|
+
Add `config/initializers/rails_settings.rb`
|
473
|
+
|
474
|
+
```rb
|
475
|
+
RailsSettings.configure do
|
476
|
+
self.cache_storage = ActiveSupport::Cache::RedisCacheStore.new(url: "redis://localhost:6379")
|
477
|
+
end
|
478
|
+
```
|
479
|
+
|
468
480
|
## Scoped Settings
|
469
481
|
|
470
482
|
> 🚨 BREAK CHANGES WARNING:
|
@@ -505,6 +517,6 @@ end
|
|
505
517
|
- [texterify/texterify](https://github.com/texterify/texterify) - 2.x
|
506
518
|
- [mastodon/mastodon](https://github.com/mastodon/mastodon) - 0.6.x
|
507
519
|
- [helpyio/helpy](https://github.com/helpyio/helpy) - 0.5.x
|
508
|
-
- [
|
520
|
+
- [maybe-finance/maybe](https://github.com/maybe-finance/maybe) - 2.x
|
509
521
|
|
510
522
|
And more than [1K repositories](https://github.com/huacnlee/rails-settings-cached/network/dependents) used.
|
data/lib/rails-settings/base.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RailsSettings
|
4
|
-
class ProtectedKeyError < RuntimeError
|
5
|
-
def initialize(key)
|
6
|
-
super("Can't use #{key} as setting key.")
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
4
|
class Base < ActiveRecord::Base
|
11
5
|
PROTECTED_KEYS = %w[var value]
|
12
6
|
self.table_name = table_name_prefix + "settings"
|
13
7
|
|
8
|
+
after_commit :clear_cache, on: %i[create update destroy]
|
9
|
+
|
14
10
|
# get the value field, YAML decoded
|
15
11
|
def value
|
16
12
|
# rubocop:disable Security/YAMLLoad
|
@@ -33,7 +29,7 @@ module RailsSettings
|
|
33
29
|
class << self
|
34
30
|
def clear_cache
|
35
31
|
RequestCache.reset
|
36
|
-
|
32
|
+
cache_storage.delete(cache_key)
|
37
33
|
end
|
38
34
|
|
39
35
|
def field(key, **opts)
|
@@ -127,13 +123,17 @@ module RailsSettings
|
|
127
123
|
end
|
128
124
|
|
129
125
|
def _all_settings
|
130
|
-
RequestCache.all_settings ||=
|
126
|
+
RequestCache.all_settings ||= cache_storage.fetch(cache_key, expires_in: 1.week) do
|
131
127
|
vars = unscoped.select("var, value")
|
132
128
|
result = {}
|
133
129
|
vars.each { |record| result[record.var] = record.value }
|
134
130
|
result.with_indifferent_access
|
135
131
|
end
|
136
132
|
end
|
133
|
+
|
134
|
+
def cache_storage
|
135
|
+
RailsSettings.config.cache_storage
|
136
|
+
end
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsSettings
|
4
|
+
class Configuration
|
5
|
+
# Caching storage backend.
|
6
|
+
# Default: `Rails.cache`
|
7
|
+
attr_accessor :cache_storage
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def config
|
12
|
+
return @config if defined?(@config)
|
13
|
+
|
14
|
+
@config = Configuration.new
|
15
|
+
@config.cache_storage = Rails.cache
|
16
|
+
@config
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure(&block)
|
20
|
+
config.instance_exec(&block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,10 +2,6 @@
|
|
2
2
|
|
3
3
|
module RailsSettings
|
4
4
|
class Railtie < Rails::Railtie
|
5
|
-
initializer "rails_settings.active_record.initialization" do
|
6
|
-
RailsSettings::Base.after_commit :clear_cache, on: %i[create update destroy]
|
7
|
-
end
|
8
|
-
|
9
5
|
initializer "rails_settings.configure_rails_initialization" do |app|
|
10
6
|
app.middleware.use RailsSettings::Middleware
|
11
7
|
end
|
@@ -9,13 +9,21 @@ require_relative "rails-settings/fields/hash"
|
|
9
9
|
require_relative "rails-settings/fields/integer"
|
10
10
|
require_relative "rails-settings/fields/string"
|
11
11
|
|
12
|
-
require_relative "rails-settings/
|
12
|
+
require_relative "rails-settings/configuration"
|
13
13
|
require_relative "rails-settings/request_cache"
|
14
14
|
require_relative "rails-settings/middleware"
|
15
15
|
require_relative "rails-settings/railtie"
|
16
16
|
require_relative "rails-settings/version"
|
17
17
|
|
18
18
|
module RailsSettings
|
19
|
+
class ProtectedKeyError < RuntimeError
|
20
|
+
def initialize(key)
|
21
|
+
super("Can't use #{key} as setting key.")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
autoload :Base, "rails-settings/base"
|
26
|
+
|
19
27
|
module Fields
|
20
28
|
end
|
21
29
|
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.9.
|
4
|
+
version: 2.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/generators/settings/templates/model.rb
|
128
128
|
- lib/rails-settings-cached.rb
|
129
129
|
- lib/rails-settings/base.rb
|
130
|
+
- lib/rails-settings/configuration.rb
|
130
131
|
- lib/rails-settings/fields/array.rb
|
131
132
|
- lib/rails-settings/fields/base.rb
|
132
133
|
- lib/rails-settings/fields/big_decimal.rb
|
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
- !ruby/object:Gem::Version
|
159
160
|
version: '0'
|
160
161
|
requirements: []
|
161
|
-
rubygems_version: 3.
|
162
|
+
rubygems_version: 3.5.3
|
162
163
|
signing_key:
|
163
164
|
specification_version: 4
|
164
165
|
summary: The best solution for store global settings in Rails applications.
|