ultra_settings 2.4.5 → 2.5.0

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: 0100a325a4565201a02667584d60b608a1fa0953c35a18c77ab014c205578853
4
- data.tar.gz: 7728dd534db12acac88f7f9c23ee4cee76dddba40d7b89ba23f2873bcc873fe3
3
+ metadata.gz: b07db0c8343574b5e9356dfed5e8752596df84920aa3136945e4fbf9d26c88b7
4
+ data.tar.gz: 8d8b1a0d5134d9eb7e6d16a873a1c98d506a17e1e458cca704f6bf0f42a75dfb
5
5
  SHA512:
6
- metadata.gz: ae0580fb25bdad6baddec3ca0ba78bb506df187889ba976487280a850e931fbcb55d52684dfe06e46d38364432954ae87cb20e6c6fa7bcd530d7476bb9d7651e
7
- data.tar.gz: 591b48efe616f8e288ecc1b5bdc1c116a2d4babcb0c32463eb5fe53ce1a7dffc739a762e46bdf54863e4f24dd5a245b47e515c64342e5c17916c76aab8638c93
6
+ metadata.gz: 29414f841f3fb1d365bff0c590b9bbc070e46363aff9efeba31d7d92ff7b5992787d414e923e2b7aca9b767e6e61d9db53b9baccb990779ab0eeb67485d422fd
7
+ data.tar.gz: 646aa68cfa787a46a447b78f82b4ecbc37c4cf841a2217c426a2610464db735f33e1e5dbdd7441c1e2e9ee329eda194ec875bac726ed8df01ca37eaac9d4d91b
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ 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.5.0
8
+
9
+ ### Added
10
+
11
+ - Added mechanism for guarding against using runtime settings during initialization with the `UltraSettings::UninitializedRuntimeSettings` class.
12
+
13
+ ### Changed
14
+
15
+ - Runtime settings will now try to load arrays from runtime settings using the `array` method if it is defined. This provides for better integration with the `super_settings` gem to avoid coercing values to and from strings.
16
+
7
17
  ## 2.4.5
8
18
 
9
19
  ### Fixed
data/README.md CHANGED
@@ -170,6 +170,8 @@ end
170
170
  UltraSettings.runtime_settings = RedisRuntimeSettings.new
171
171
  ```
172
172
 
173
+ The runtime settings implementation may also define an `array` method that takes a single parameter to return an array value. If this method is not implemented, then array values must be returned as single line CSV strings.
174
+
173
175
  #### Using the `super_settings` gem
174
176
 
175
177
  There is a companion gem [super_settings](https://github.com/bdurand/super_settings) that can be used as a drop in implementation for the runtime settings. You just need to set the runtime settings to the `SuperSettings` object.
@@ -178,6 +180,21 @@ There is a companion gem [super_settings](https://github.com/bdurand/super_setti
178
180
  UltraSettings.runtime_settings = SuperSettings
179
181
  ```
180
182
 
183
+ #### Initialization Issues
184
+
185
+ Runtime settings should not be used during application initialization. Often the values set during initialization are static so it can be misleading to use runtime settings for them. There can also be race conditions where the runtime settings implementation itself needs to be initialized. You can guard against unintended usage of runtime settings during initialization by using the `UltraSettings::UninitializedRuntimeSettings` class. This class will raise an error if you try to access a setting before the runtime settings have been initialized.
186
+
187
+ ```ruby
188
+ # Set the runtime settings to the uninitialized class to raise errors if anything tries to use
189
+ # reference a runtime setting during initializaton.
190
+ UltraSettings.runtime_settings = UltraSettings::UninitializedRuntimeSettings
191
+
192
+ # Switch to using the super_settings gem after the ActiveRecord has been initialized.
193
+ ActiveSupport.on_load(:active_record) do
194
+ UltraSettings.runtime_settings = SuperSettings
195
+ end
196
+ ```
197
+
181
198
  #### Customizing Runtime Settings
182
199
 
183
200
  By default settings will be loaded from runtime settings by constructing a prefix from the configuration class name (i.e. `Configs::MySettingsConfiguration` uses the prefix `configs.my_settings.`) with the field name appended to it (e.g. `configs.my_settings.host`). By default runtime settings will be in all lowercase letters.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.4.5
1
+ 2.5.0
@@ -99,7 +99,7 @@ module UltraSettings
99
99
  value = env[env_var] if env && env_var
100
100
  value = nil if value == ""
101
101
  if value.nil?
102
- value = settings[runtime_setting] if settings && runtime_setting
102
+ value = runtime_setting_value(settings)
103
103
  value = nil if value == ""
104
104
  if value.nil?
105
105
  value = yaml_value(yaml_config)
@@ -117,6 +117,18 @@ module UltraSettings
117
117
  [value, source]
118
118
  end
119
119
 
120
+ def runtime_setting_value(settings)
121
+ return nil unless settings && runtime_setting
122
+
123
+ if type == :array && settings.respond_to?(:array)
124
+ if settings.method(:array).parameters.count { |ptype, pname| ptype == :req } == 1
125
+ return settings.array(runtime_setting)
126
+ end
127
+ end
128
+
129
+ settings[runtime_setting]
130
+ end
131
+
120
132
  def yaml_value(yaml_config)
121
133
  return nil unless yaml_config && yaml_key
122
134
 
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UltraSettings
4
+ # This class is used to represent runtime settings that have not been initialized yet.
5
+ # You can use this to protect your application from accidentally accessing runtime settings
6
+ # before they are initialized. Doing this can cquse unexpected behavior if the runtime settings
7
+ # engine has not yet been initialized. For instance, if your runtime settings enging reads from
8
+ # a database it would not be available until the database connection is established.
9
+ #
10
+ # The intention of this class is to set it a the runtime settings at the beginning of initialization
11
+ # and then set the actual runtime settings engine after the initialization is complete. It will
12
+ # act as a guard to prevent invalid runtime settings backed configurations from being used during
13
+ # initialization.
14
+ #
15
+ # @example
16
+ #
17
+ # UltraSettings.runtime_settings = UltraSettings::UninitializedRuntimeSettings
18
+ # ActiveSupport.on_load(:active_record) do
19
+ # UltraSettings.runtime_settings = SuperSettings
20
+ # end
21
+ class UninitializedRuntimeSettings
22
+ class Error < StandardError
23
+ end
24
+
25
+ class << self
26
+ def [](key)
27
+ raise Error.new("Attempt to call runtime setting #{key} during initialization")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -16,6 +16,7 @@ require_relative "ultra_settings/rack_app"
16
16
  require_relative "ultra_settings/web_view"
17
17
  require_relative "ultra_settings/application_view"
18
18
  require_relative "ultra_settings/configuration_view"
19
+ require_relative "ultra_settings/uninitialized_runtime_settings"
19
20
  require_relative "ultra_settings/yaml_config"
20
21
  require_relative "ultra_settings/version"
21
22
 
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.4.5
4
+ version: 2.5.0
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-12-11 00:00:00.000000000 Z
11
+ date: 2025-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,7 @@ files:
52
52
  - lib/ultra_settings/field.rb
53
53
  - lib/ultra_settings/rack_app.rb
54
54
  - lib/ultra_settings/railtie.rb
55
+ - lib/ultra_settings/uninitialized_runtime_settings.rb
55
56
  - lib/ultra_settings/version.rb
56
57
  - lib/ultra_settings/web_view.rb
57
58
  - lib/ultra_settings/yaml_config.rb