ultra_settings 2.3.0 → 2.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a9fddef64ed0564d8ead06ae79465a37fdb50a55407139cacc121714475ac6f
4
- data.tar.gz: a26020c7d81154d3e000bba327e3a6cb53ab00ae9847ed2f96999ff18d431241
3
+ metadata.gz: c4d6c86b8bbf3af68e92cc311d50ba5a10c72479b466047b6789b0bdd5aae566
4
+ data.tar.gz: af86a79d963a42b66b870706a7e47a025b03b59365b63354faec5003f2839087
5
5
  SHA512:
6
- metadata.gz: 066b922fcc7232a33eee6e6b52924d1efc51d3a4e500f4680f8e03a1feb7a6414a22b55f9b5672e35db7aeb958566fc1685ba39fed8a9f568840af2b60a7b3e2
7
- data.tar.gz: b95942f92c5010decb55da413fdd2c9f070ebafef2815ab5bd4f781f803b744c502b98598fc14b4e5338ec7026fd7a1c5b11011136afe4507a0eeb436dac632b
6
+ metadata.gz: 106b3a42b408d389b59b759e9639f38ae10a538aec7046d37d496373483a33174a2505bc44c8c012e14f39a7215358b7863487fbc209f68bce8b132258aa9624
7
+ data.tar.gz: 5044a165b1129aba0c2678f0e9f9fe53e75516a37f50cc76d2c134850f37e38e81d56d53864ba980c3cbd36c704141f0a7434e371eb7210bef0d4f601640611c
data/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 2.4.1
8
+
9
+ ### Changed
10
+
11
+ - Ignore base configuration classes that don't have any fields defined in the web UI.
12
+ - Allow overriding values on static fields in tests.
13
+ - Changed Web UI CSS variable scope to apply to all application elements.
14
+
15
+ ## 2.4.0
16
+
17
+ ### Added
18
+
19
+ - Added the `UltraSettings::ConfigHelper` module to add convenience methods `config` on the class and instance.
20
+
7
21
  ## 2.3.0
8
22
 
9
23
  ### Added
data/README.md CHANGED
@@ -324,24 +324,40 @@ end
324
324
  Rails.application.settings.my_service.host
325
325
  ```
326
326
 
327
- #### Using a Helper Method
328
-
329
- To keep your codebase clean, especially if most configurations are accessed from within a specific class, you can encapsulate the configuration access in a helper method.
327
+ #### Using Helper Methods
330
328
 
329
+ To streamline configuration access and keep your codebase clean, especially when configurations are frequently accessed within specific classes, you can encapsulate configuration access in a helper method:
331
330
 
332
331
  ```ruby
333
332
  class MyService
334
-
335
- # Reference the value as `settings.host`
333
+ def api_key
334
+ config.api_key
335
+ end
336
336
 
337
337
  private
338
338
 
339
- def settings
339
+ def config
340
340
  MyServiceConfiguration.instance
341
341
  end
342
342
  end
343
343
  ```
344
344
 
345
+ #### Leveraging UltraSettings::ConfigHelper
346
+
347
+ For added convenience, you can use the UltraSettings::ConfigHelper module to automatically generate helper methods for accessing configurations at both the class and instance levels:
348
+
349
+ ```ruby
350
+ class MyService
351
+
352
+ extend UltraSettings::ConfigHelper
353
+ configuration_class MyServiceConfiguration
354
+
355
+ # Adds these helper methods:
356
+ # - MyService.config
357
+ # - MyService.new.config
358
+ end
359
+ ```
360
+
345
361
  ### Web UI
346
362
 
347
363
  UltraSettings provides a web UI via a mountable Rack application. You can use this to view the settings values and documentation. The UI will not display the value of any setting marked as secret.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.4.1
data/app/application.css CHANGED
@@ -62,4 +62,4 @@
62
62
  -webkit-appearance: none;
63
63
  -moz-appearance: none;
64
64
  appearance: none;
65
- }
65
+ }
@@ -1,5 +1,5 @@
1
1
  <% unless color_scheme == :dark %>
2
- .ultra-settings-configuration {
2
+ .ultra-settings {
3
3
  --table-header-bg-color: #fff;
4
4
  --table-border-color: #dee2e6;
5
5
  --alt-row-color: rgba(0, 0, 0, .05);
@@ -15,7 +15,7 @@
15
15
  @media (prefers-color-scheme: dark) {
16
16
  <% end %>
17
17
  <% if color_scheme == :system || color_scheme == :dark %>
18
- .ultra-settings-configuration {
18
+ .ultra-settings {
19
19
  --table-header-bg-color: #333;
20
20
  --table-border-color: #555;
21
21
  --alt-row-color: rgba(0, 0, 0, .30);
data/app/index.html.erb CHANGED
@@ -1,20 +1,26 @@
1
- <div class="ultra-settings-nav">
2
- <form onsubmit="return false" style="margin-bottom: 0.5rem;">
3
- <select class="<%= html_escape(select_class) %>" size="1" id="config-selector">
4
- <% UltraSettings.__configuration_names__.sort.each do |name| %>
5
- <option value="config-<%= html_escape(name) %>"><%= html_escape(UltraSettings.send(name).class.name) %></option>
6
- <% end %>
7
- </select>
8
- </form>
9
- </div>
10
-
11
- <% UltraSettings.__configuration_names__.sort.each do |name| %>
12
- <% configuration = UltraSettings.send(name) %>
1
+ <div class="ultra-settings">
2
+ <div class="ultra-settings-nav">
3
+ <form onsubmit="return false" style="margin-bottom: 0.5rem;">
4
+ <select class="<%= html_escape(select_class) %>" size="1" id="config-selector">
5
+ <% UltraSettings.__configuration_names__.sort.each do |name| %>
6
+ <% configuration = UltraSettings.send(name) %>
7
+ <% next if configuration.class.fields.empty? %>
13
8
 
14
- <div class="ultra-settings-configuration" id="config-<%= html_escape(name) %>" style="display:none;">
15
- <%= UltraSettings::ConfigurationView.new(configuration).render(table_class: table_class) %>
9
+ <option value="config-<%= html_escape(name) %>"><%= html_escape(UltraSettings.send(name).class.name) %></option>
10
+ <% end %>
11
+ </select>
12
+ </form>
16
13
  </div>
17
- <% end %>
14
+
15
+ <% UltraSettings.__configuration_names__.sort.each do |name| %>
16
+ <% configuration = UltraSettings.send(name) %>
17
+ <% next if configuration.class.fields.empty? %>
18
+
19
+ <div class="ultra-settings-configuration" id="config-<%= html_escape(name) %>" style="display:none;">
20
+ <%= UltraSettings::ConfigurationView.new(configuration).render(table_class: table_class) %>
21
+ </div>
22
+ <% end %>
23
+ </div>
18
24
 
19
25
  <script>
20
26
  <%= javascript %>
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UltraSettings
4
+ # Helper module for setting up a class to use the config methods
5
+ #
6
+ # Usage:
7
+ # class TestClass
8
+ # extend UltraSettings::ConfigHelper
9
+ # configuration_class TestConfiguration
10
+ # end
11
+ # TestClass.config => TestConfiguration.instance
12
+ # TestClass.new.config => TestConfiguration.instance
13
+ module ConfigHelper
14
+ def configuration_class(config_class)
15
+ define_singleton_method :config do
16
+ config_class.instance
17
+ end
18
+
19
+ define_method :config do
20
+ self.class.config
21
+ end
22
+ end
23
+ end
24
+ end
@@ -533,11 +533,14 @@ module UltraSettings
533
533
  field = self.class.send(:defined_fields)[name]
534
534
  return nil unless field
535
535
 
536
- if field.static? && @ultra_settings_memoized_values.include?(name)
536
+ use_override = @ultra_settings_override_values[Thread.current.object_id]&.include?(name)
537
+
538
+ if field.static? && !use_override && @ultra_settings_memoized_values.include?(name)
537
539
  return @ultra_settings_memoized_values[name]
538
540
  end
539
541
 
540
- if @ultra_settings_override_values[Thread.current.object_id]&.include?(name)
542
+ value = nil
543
+ if use_override
541
544
  value = field.coerce(@ultra_settings_override_values[Thread.current.object_id][name])
542
545
  else
543
546
  env = ENV if field.env_var
@@ -551,7 +554,7 @@ module UltraSettings
551
554
  value = field.default
552
555
  end
553
556
 
554
- if field.static?
557
+ if field.static? && !use_override
555
558
  @ultra_settings_mutex.synchronize do
556
559
  if @ultra_settings_memoized_values.include?(name)
557
560
  value = @ultra_settings_memoized_values[name]
@@ -68,7 +68,7 @@ module UltraSettings
68
68
  else
69
69
  "Value: #{display_value(value)}"
70
70
  end
71
- "<dfn title=\"#{html_escape(title)}\">#{html_escape(label)}</dfn>"
71
+ "<dfn style=\"text-decoration: underline dotted;\" title=\"#{html_escape(title)}\">#{html_escape(label)}</dfn>"
72
72
  end
73
73
 
74
74
  def secret_value(value)
@@ -10,6 +10,7 @@ require "uri"
10
10
 
11
11
  require_relative "ultra_settings/configuration"
12
12
  require_relative "ultra_settings/coerce"
13
+ require_relative "ultra_settings/config_helper"
13
14
  require_relative "ultra_settings/field"
14
15
  require_relative "ultra_settings/rack_app"
15
16
  require_relative "ultra_settings/web_view"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultra_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-12 00:00:00.000000000 Z
11
+ date: 2024-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -46,6 +46,7 @@ files:
46
46
  - lib/ultra_settings.rb
47
47
  - lib/ultra_settings/application_view.rb
48
48
  - lib/ultra_settings/coerce.rb
49
+ - lib/ultra_settings/config_helper.rb
49
50
  - lib/ultra_settings/configuration.rb
50
51
  - lib/ultra_settings/configuration_view.rb
51
52
  - lib/ultra_settings/field.rb