ultra_settings 2.10.0 → 2.10.1

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/README.md +18 -0
  4. data/VERSION +1 -1
  5. data/app/_config_description.html.erb +10 -1
  6. data/app/_data_source.html.erb +2 -2
  7. data/app/application.css +116 -24
  8. data/app/application_vars.css.erb +30 -12
  9. data/app/configuration.html.erb +19 -1
  10. data/app/layout.css +5 -5
  11. data/app/layout_vars.css.erb +4 -4
  12. data/app/locales/ar.json +5 -2
  13. data/app/locales/cs.json +5 -2
  14. data/app/locales/da.json +5 -2
  15. data/app/locales/de.json +5 -2
  16. data/app/locales/el.json +5 -2
  17. data/app/locales/en.json +5 -2
  18. data/app/locales/es.json +5 -2
  19. data/app/locales/fa.json +5 -2
  20. data/app/locales/fr.json +5 -2
  21. data/app/locales/gd.json +5 -2
  22. data/app/locales/he.json +5 -2
  23. data/app/locales/hi.json +5 -2
  24. data/app/locales/it.json +5 -2
  25. data/app/locales/ja.json +5 -2
  26. data/app/locales/ko.json +5 -2
  27. data/app/locales/lt.json +5 -2
  28. data/app/locales/nb.json +5 -2
  29. data/app/locales/nl.json +5 -2
  30. data/app/locales/pl.json +5 -2
  31. data/app/locales/pt-br.json +5 -2
  32. data/app/locales/pt.json +5 -2
  33. data/app/locales/ru.json +5 -2
  34. data/app/locales/sv.json +5 -2
  35. data/app/locales/ta.json +5 -2
  36. data/app/locales/tr.json +5 -2
  37. data/app/locales/uk.json +5 -2
  38. data/app/locales/ur.json +5 -2
  39. data/app/locales/vi.json +5 -2
  40. data/app/locales/zh-cn.json +5 -2
  41. data/app/locales/zh-tw.json +5 -2
  42. data/lib/ultra_settings/application_view.rb +13 -4
  43. data/lib/ultra_settings/audit_data_sources.rb +1 -1
  44. data/lib/ultra_settings/coerce.rb +1 -1
  45. data/lib/ultra_settings/configuration.rb +36 -10
  46. data/lib/ultra_settings/configuration_view.rb +166 -9
  47. data/lib/ultra_settings/mini_i18n.rb +14 -10
  48. data/lib/ultra_settings/rack_app.rb +4 -4
  49. data/lib/ultra_settings/view_helper.rb +27 -5
  50. data/lib/ultra_settings/web_view.rb +17 -10
  51. data/lib/ultra_settings/yaml_config.rb +10 -2
  52. data/lib/ultra_settings.rb +57 -1
  53. data/ultra_settings.gemspec +1 -1
  54. metadata +2 -2
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "erb"
4
4
  require "yaml"
5
+ require "date"
5
6
  require "time"
6
7
  require "pathname"
7
8
  require "singleton"
@@ -32,6 +33,10 @@ module UltraSettings
32
33
 
33
34
  VALID_NAME_PATTERN = /\A[a-z_][a-zA-Z0-9_]*\z/
34
35
 
36
+ # Thread local key used to make the runtime settings reload in the web views reentrant.
37
+ RELOAD_GUARD_KEY = :ultra_settings_runtime_settings_reloaded
38
+ private_constant :RELOAD_GUARD_KEY
39
+
35
40
  @configurations = {}
36
41
  @mutex = Mutex.new
37
42
  @runtime_settings = nil
@@ -177,6 +182,57 @@ module UltraSettings
177
182
  @runtime_settings
178
183
  end
179
184
 
185
+ # Reload the runtime settings cache and then yield to the block. The web views call
186
+ # this when rendering so that a setting changed from the UI is displayed on the next
187
+ # page load rather than whenever the runtime settings engine gets around to
188
+ # refreshing itself.
189
+ #
190
+ # The runtime settings object is reloaded if it responds to `load_settings`. The
191
+ # `super_settings` gem does, as does anything that delegates to it.
192
+ #
193
+ # Calls are reentrant, so a block that renders several views only reloads once.
194
+ # Wrap a page that embeds more than one `ConfigurationView` in this method to avoid
195
+ # reloading the runtime settings once per view.
196
+ #
197
+ # Errors are not fatal; the page can still show values from the other sources.
198
+ #
199
+ # @example Rendering several configurations with a single reload.
200
+ # UltraSettings.with_runtime_settings_reloaded do
201
+ # configurations.each { |config| output << UltraSettings::ConfigurationView.new(config).render }
202
+ # end
203
+ #
204
+ # @return [Object] The result of the block.
205
+ def with_runtime_settings_reloaded
206
+ return yield if Thread.current[RELOAD_GUARD_KEY]
207
+
208
+ Thread.current[RELOAD_GUARD_KEY] = true
209
+ begin
210
+ settings = __runtime_settings__
211
+ if settings.respond_to?(:load_settings)
212
+ begin
213
+ settings.load_settings
214
+ rescue => e
215
+ warn("UltraSettings: unable to reload runtime settings: #{e.class}: #{e.message}")
216
+ end
217
+ end
218
+
219
+ yield
220
+ ensure
221
+ Thread.current[RELOAD_GUARD_KEY] = nil
222
+ end
223
+ end
224
+
225
+ # Returns true if the application is running in development mode. This is used by the
226
+ # web UI to decide if templates, stylesheets, and translations can be cached in memory
227
+ # or if they need to be re-read from disk on every request.
228
+ #
229
+ # @return [Boolean]
230
+ # @api private
231
+ def __development_mode__?
232
+ env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || ENV["APP_ENV"] || "development"
233
+ env == "development"
234
+ end
235
+
180
236
  # Set the URL for changing runtime settings. If this is set, then a link to the
181
237
  # URL will be displayed in the web view for fields that support runtime settings.
182
238
  # The URL may contain a `${name}` placeholder that will be replaced with the name
@@ -266,7 +322,7 @@ module UltraSettings
266
322
  settings = settings.to_a
267
323
  config_name, values = settings.first
268
324
  config_name = config_name.to_s
269
- other_settings = settings[1..-1]
325
+ other_settings = settings[1..]
270
326
 
271
327
  unless @configurations.include?(config_name)
272
328
  raise ArgumentError.new("Unknown configuration: #{config_name.inspect}")
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
38
38
 
39
39
  spec.require_paths = ["lib"]
40
40
 
41
- spec.required_ruby_version = ">= 2.5"
41
+ spec.required_ruby_version = ">= 2.6"
42
42
 
43
43
  spec.add_development_dependency "bundler"
44
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultra_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: '2.5'
113
+ version: '2.6'
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="