rails-settings-cached 2.0.1 → 2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc90c161735c2de3ceef1814d8c93706422860bfa444407717862ded1ee4efb4
4
- data.tar.gz: 50538a15a02ad109a05ef5d09bebe2a2dc4530f8b393348f4a86b32521fb3917
3
+ metadata.gz: 2f5d17c59cd0c8b1c7c587169c32a7b7003c9067086a7b43e40d716973c8b104
4
+ data.tar.gz: 9e4b276543867580abcfa9da999fe3e81303459df28db49c76f2e75bef6679e7
5
5
  SHA512:
6
- metadata.gz: b3b3c1d7730b48f11a90c5d1a0ff9ee07dccade17b7dd31ce6fb8988449a12a265cbb8349c61416d7663ea7e629fa92f41ea4756e44c2b862522f7172a81f3ee
7
- data.tar.gz: 116a49dc9ea61533e11c0ccad5ec0138093db6f051b6319219259e084e2c4fa2bca06e098d939b6de0c1e3ca4dadd533a0fa0c5db939c2ea15c187c623e9c1cf
6
+ metadata.gz: 4be5e67948d944b2daa60c574586e297b638fc17e828a4923dc010ad691402b69bd8b06c823b228a3eaedafbd00fc2796d43c7986cb34a3bc0e5ae401eae8647
7
+ data.tar.gz: 7021a6b8d97b31f3f28557f51bef405cf5cfba5ed2194ee50d1b56ce599e1ca1aa288498d39c3ceefadd0618781610bd12344cf468b826ee4b7125fc640ce267
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rails Settings Cached
1
+ ## Rails Settings Cached
2
2
 
3
3
  This a plugin that makes managing a table of
4
4
  global key, value pairs easy. Think of it like a global Hash stored in your database,
@@ -130,6 +130,28 @@ irb > Setting.notification_options
130
130
  }
131
131
  ```
132
132
 
133
+ ## Readonly field
134
+
135
+ Some times you may need use Setting before Rails initialize, for example `config/devise.rb`
136
+
137
+ ```rb
138
+ Devise.setup do |config|
139
+ if Setting.omniauth_google_client_id.present?
140
+ config.omniauth :google_oauth2, Setting.omniauth_google_client_id, Setting.omniauth_google_client_secret
141
+ end
142
+ end
143
+ ```
144
+
145
+ In this case, you must define the `readonly` field:
146
+
147
+ ```rb
148
+ class Setting < RailsSettings::Base
149
+ # cache_prefix { "v1" }
150
+ field :omniauth_google_client_id, default: ENV["OMNIAUTH_GOOGLE_CLIENT_ID"], readonly: true
151
+ field :omniauth_google_client_secret, default: ENV["OMNIAUTH_GOOGLE_CLIENT_SECRET"], readonly: true
152
+ end
153
+ ```
154
+
133
155
  ### Caching flow:
134
156
 
135
157
  ```
@@ -155,6 +177,16 @@ class Setting < RailsSettings::Base
155
177
  end
156
178
  ```
157
179
 
180
+ In testing, you need add `Setting.clear_cache` for each Test case:
181
+
182
+ ```rb
183
+ class ActiveSupport::TestCase
184
+ teardown do
185
+ Setting.clear_cache
186
+ end
187
+ end
188
+ ```
189
+
158
190
  -----
159
191
 
160
192
  ## How to manage Settings in admin interface?
@@ -17,12 +17,16 @@ module RailsSettings
17
17
  self[:value] = new_value.to_yaml
18
18
  end
19
19
 
20
- def expire_cache
21
- Thread.current[:rails_settings_all_settings] = nil
22
- Rails.cache.delete(self.class.cache_key)
20
+ def clear_cache
21
+ self.class.clear_cache
23
22
  end
24
23
 
25
24
  class << self
25
+ def clear_cache
26
+ Thread.current[:rails_settings_all_settings] = nil
27
+ Rails.cache.delete(self.cache_key)
28
+ end
29
+
26
30
  def field(key, **opts)
27
31
  _define_field(key, default: opts[:default], type: opts[:type], readonly: opts[:readonly])
28
32
  end
@@ -74,8 +78,7 @@ module RailsSettings
74
78
 
75
79
  if type == :boolean
76
80
  self.class.define_method("#{key}?") do
77
- val = self.send(:_value_of, key)
78
- val == "true" || val == "1"
81
+ self.send(key)
79
82
  end
80
83
  end
81
84
  end
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class Railtie < Rails::Railtie
5
5
  initializer "rails_settings.active_record.initialization" do
6
- RailsSettings::Base.after_commit :expire_cache, on: %i(create update destroy)
6
+ RailsSettings::Base.after_commit :clear_cache, on: %i(create update destroy)
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class << self
5
5
  def version
6
- "2.0.1"
6
+ "2.0.2"
7
7
  end
8
8
  end
9
9
  end
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: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee