ultra_settings 2.4.4 → 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 +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +27 -0
- data/VERSION +1 -1
- data/lib/ultra_settings/configuration.rb +5 -0
- data/lib/ultra_settings/field.rb +13 -1
- data/lib/ultra_settings/railtie.rb +1 -0
- data/lib/ultra_settings/uninitialized_runtime_settings.rb +31 -0
- data/lib/ultra_settings.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b07db0c8343574b5e9356dfed5e8752596df84920aa3136945e4fbf9d26c88b7
|
4
|
+
data.tar.gz: 8d8b1a0d5134d9eb7e6d16a873a1c98d506a17e1e458cca704f6bf0f42a75dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29414f841f3fb1d365bff0c590b9bbc070e46363aff9efeba31d7d92ff7b5992787d414e923e2b7aca9b767e6e61d9db53b9baccb990779ab0eeb67485d422fd
|
7
|
+
data.tar.gz: 646aa68cfa787a46a447b78f82b4ecbc37c4cf841a2217c426a2610464db735f33e1e5dbdd7441c1e2e9ee329eda194ec875bac726ed8df01ca37eaac9d4d91b
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,22 @@ 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
|
+
|
17
|
+
## 2.4.5
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
- Add check for nil YAML config path to avoid error loading YAML file if the path is not set.
|
22
|
+
|
7
23
|
## 2.4.4
|
8
24
|
|
9
25
|
### Changed
|
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.
|
@@ -261,6 +278,16 @@ While for production, the values would be the combination of `production` and `s
|
|
261
278
|
|
262
279
|
In a Rails application, the YAML environment will be set to the Rails environment and YAML files will be assumed to exist in the `config` directory.
|
263
280
|
|
281
|
+
If want to use configuration objects in code that is initialized with the Rails application before initializers are run, then you'll need to setup the configuration manually.
|
282
|
+
|
283
|
+
For instance, if you want to create a `DatabaseConfiguration` class that is used in the ERB code in `database.yml`, then you'll need to setup the configuration before the Rails application is initialized in `application.rb`.
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
UltraSettings.yaml_config_env = Rails.env
|
287
|
+
UltraSettings.yaml_config_path = __dir__
|
288
|
+
require_relative '../app/configurations/database_configuration'
|
289
|
+
```
|
290
|
+
|
264
291
|
### Removing The Hierarchy
|
265
292
|
|
266
293
|
If you prefer not to use the default hierarchy of environment variables, runtime settings, and YAML files, you can disable it. This allows you to explicitly define which data sources should be used for each field.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.0
|
@@ -158,6 +158,9 @@ module UltraSettings
|
|
158
158
|
# @return [Pathname, nil]
|
159
159
|
def configuration_file
|
160
160
|
unless defined?(@configuration_file)
|
161
|
+
default_file = default_configuration_file
|
162
|
+
return nil if default_file.nil?
|
163
|
+
|
161
164
|
@configuration_file = default_configuration_file
|
162
165
|
end
|
163
166
|
return nil? unless @configuration_file
|
@@ -383,6 +386,8 @@ module UltraSettings
|
|
383
386
|
end
|
384
387
|
|
385
388
|
def default_configuration_file
|
389
|
+
return nil if yaml_config_path.nil?
|
390
|
+
|
386
391
|
path = Pathname.new(yaml_config_path)
|
387
392
|
path.join(*"#{root_name}.yml".split("/"))
|
388
393
|
end
|
data/lib/ultra_settings/field.rb
CHANGED
@@ -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
|
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
|
|
@@ -9,6 +9,7 @@ module UltraSettings
|
|
9
9
|
config.ultra_settings = ActiveSupport::OrderedOptions.new
|
10
10
|
config.ultra_settings.auto_load_directories ||= [File.join("app", "configurations")]
|
11
11
|
|
12
|
+
# initializer "ultra_settings.before_bootstrap", before: :bootstrap_hook do
|
12
13
|
config.before_configuration do
|
13
14
|
UltraSettings::Configuration.yaml_config_env ||= Rails.env
|
14
15
|
UltraSettings::Configuration.yaml_config_path ||= Rails.root.join("config")
|
@@ -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
|
data/lib/ultra_settings.rb
CHANGED
@@ -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
|
+
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:
|
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
|