rails-settings-cached 2.7.1 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70c3d68c88fbd1a2a3cc1e9f78a45e06fc7b7a6df4698137e2a4ea6c77a27e33
4
- data.tar.gz: fd6ecee62edad7a5ca942fbe7e102ae6e3f075ea471e120dcc5a5f1d5f3fdb33
3
+ metadata.gz: 5f078f79f76ec1145cb095d269ea6a4772e8959b0eeaedec1ed607a23189fc5b
4
+ data.tar.gz: bd0105aebf763f4bce9041c459f6464f827ce1459ed3b83614342f1f285bfe7d
5
5
  SHA512:
6
- metadata.gz: 0d0c55d7a8f19adbfa81868c76a1d36f67aa37d27ad33051b7a8bf6ec323d0d4b57cc442c29b43be8c8799cfa3968f958f29fb1f104230dc79478294f09d2a59
7
- data.tar.gz: 699e9e77f1d4d130e9493c7c379f1aade95b7f589401652912741f5e13eec4816b0a8eee308b55504ad3acfc2613af41113051d6a5655df399d27ed59015bd5f
6
+ metadata.gz: 964dad7734883af92b76ed7e4b6729e7381f15b3e2149df7fc98e07dbf869baef1460e0f0dea6de6eb0689255a4e249d55e2afdd7fdf5f3d18b0028ac407caa3
7
+ data.tar.gz: a1bc23575e4790b2c707bc644fb5d522c95338320120cb1bab1b047310c868ec7922e29853d138dc137726f75bce25f518f95a5b71a146d3e4da8b613807cb5a
data/README.md CHANGED
@@ -283,6 +283,10 @@ Rails.application.configure do
283
283
  end
284
284
  ```
285
285
 
286
+ TIP: You also can follow this file to rewrite ActionMailer's `mail` method for configuration Mail options from Setting after Rails booted.
287
+
288
+ https://github.com/ruby-china/homeland/blob/main/app/mailers/application_mailer.rb#L19
289
+
286
290
  ## Caching flow:
287
291
 
288
292
  ```
@@ -200,7 +200,7 @@ module RailsSettings
200
200
  end
201
201
 
202
202
  def _all_settings
203
- RequestCache.settings ||= Rails.cache.fetch(cache_key, expires_in: 1.week) do
203
+ RequestCache.all_settings ||= Rails.cache.fetch(cache_key, expires_in: 1.week) do
204
204
  vars = unscoped.select("var, value")
205
205
  result = {}
206
206
  vars.each { |record| result[record.var] = record.value }
@@ -0,0 +1,14 @@
1
+ module RailsSettings
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ RailsSettings::RequestCache.enable!
9
+ result = @app.call(env)
10
+ RailsSettings::RequestCache.disable!
11
+ result
12
+ end
13
+ end
14
+ end
@@ -5,5 +5,9 @@ module RailsSettings
5
5
  initializer "rails_settings.active_record.initialization" do
6
6
  RailsSettings::Base.after_commit :clear_cache, on: %i[create update destroy]
7
7
  end
8
+
9
+ initializer "rails_settings.configure_rails_initialization" do |app|
10
+ app.middleware.use RailsSettings::Middleware
11
+ end
8
12
  end
9
13
  end
@@ -1,9 +1,36 @@
1
1
  module RailsSettings
2
+ module RequestCacheGetter
3
+ extend ActiveSupport::Concern
4
+
5
+ class_methods do
6
+ def enable!
7
+ Thread.current[:rails_settings_request_cache_enable] = true
8
+ end
9
+
10
+ def disable!
11
+ Thread.current[:rails_settings_request_cache_enable] = nil
12
+ end
13
+
14
+ def enabled?
15
+ Thread.current[:rails_settings_request_cache_enable]
16
+ end
17
+
18
+ def all_settings
19
+ enabled? ? settings : nil
20
+ end
21
+
22
+ def all_settings=(val)
23
+ self.settings = val
24
+ end
25
+ end
26
+ end
27
+
2
28
  if defined? ActiveSupport::CurrentAttributes
3
29
  # For storage all settings in Current, it will reset after per request completed.
4
30
  # Base on ActiveSupport::CurrentAttributes
5
31
  # https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html
6
32
  class RequestCache < ActiveSupport::CurrentAttributes
33
+ include RequestCacheGetter
7
34
  attribute :settings
8
35
  end
9
36
  else
@@ -12,6 +39,8 @@ module RailsSettings
12
39
  require "request_store"
13
40
 
14
41
  class RequestCache
42
+ include RequestCacheGetter
43
+
15
44
  class << self
16
45
  def reset
17
46
  self.settings = nil
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class << self
5
5
  def version
6
- "2.7.1"
6
+ "2.8.0"
7
7
  end
8
8
  end
9
9
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "rails-settings/base"
4
4
  require_relative "rails-settings/request_cache"
5
+ require_relative "rails-settings/middleware"
5
6
  require_relative "rails-settings/railtie"
6
7
  require_relative "rails-settings/version"
7
8
 
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.7.1
4
+ version: 2.8.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: 2021-07-12 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: codecov
28
+ name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: pg
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rubocop
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +66,6 @@ dependencies:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: simplecov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
70
  name: sqlite3
99
71
  requirement: !ruby/object:Gem::Requirement
@@ -127,6 +99,7 @@ files:
127
99
  - lib/generators/settings/templates/model.rb
128
100
  - lib/rails-settings-cached.rb
129
101
  - lib/rails-settings/base.rb
102
+ - lib/rails-settings/middleware.rb
130
103
  - lib/rails-settings/railtie.rb
131
104
  - lib/rails-settings/request_cache.rb
132
105
  - lib/rails-settings/version.rb
@@ -149,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
122
  - !ruby/object:Gem::Version
150
123
  version: '0'
151
124
  requirements: []
152
- rubygems_version: 3.2.3
125
+ rubygems_version: 3.1.4
153
126
  signing_key:
154
127
  specification_version: 4
155
128
  summary: The best solution for store global settings in Rails applications.