ultra_settings 2.7.0 → 2.8.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.
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :ultra_settings do
4
+ desc <<~DOC
5
+ Generates a report of environment variables used in configurations that are set to their default values.
6
+ This report can help identify environment variables that are superfluous and can be removed. It skips any
7
+ environment variables that are used for secrets.
8
+ DOC
9
+ task unnecessary_env_vars: :environment do
10
+ require_relative "utils"
11
+ require_relative "../audit_data_sources"
12
+
13
+ UltraSettings::Tasks::Utils.eager_load!
14
+ env_vars_at_default = UltraSettings::AuditDataSources.unnecessary_env_vars
15
+
16
+ output = env_vars_at_default.collect do |env_var, value|
17
+ "Environment variable #{env_var} is set to its default value: #{value.inspect}"
18
+ end
19
+ puts output
20
+ end
21
+
22
+ desc <<~DOC
23
+ Generates a report of runtime settings used in configurations that are set to their default values.
24
+ This report can help identify runtime settings that are superfluous and can be removed. It skips any
25
+ runtime settings that are used for secrets.
26
+ DOC
27
+ task unnecessary_runtime_settings: :environment do
28
+ require_relative "utils"
29
+ require_relative "../audit_data_sources"
30
+
31
+ UltraSettings::Tasks::Utils.eager_load!
32
+ unnecessary_runtime_settings = UltraSettings::AuditDataSources.unnecessary_runtime_settings
33
+
34
+ output = unnecessary_runtime_settings.collect do |runtime_setting, value|
35
+ "Runtime setting #{runtime_setting} is set to its default value: #{value.inspect}"
36
+ end
37
+ puts output
38
+ end
39
+
40
+ desc <<~DOC
41
+ Generates a report of environment variables used in configurations that can be converted to runtime settings.
42
+ This report can help identify environment variables that can be removed if the corresponding runtime settings
43
+ are set. It skips any environment variables that are used for secrets.
44
+ DOC
45
+ task env_vars_can_be_runtime_setting: :environment do
46
+ require_relative "utils"
47
+ require_relative "../audit_data_sources"
48
+
49
+ UltraSettings::Tasks::Utils.eager_load!
50
+ env_vars_can_be_runtime = UltraSettings::AuditDataSources.env_vars_can_be_runtime_setting
51
+
52
+ output = env_vars_can_be_runtime.collect do |env_var, runtime_setting, value|
53
+ "Environment variable #{env_var} can be converted to runtime setting #{runtime_setting} with value: #{value.inspect}"
54
+ end
55
+ puts output
56
+ end
57
+
58
+ desc <<~DOC
59
+ Generates a report of environment variables used in configurations that do not have a default value.
60
+ This report can help identify settings that could be set in YAML or with a default value rather than via
61
+ environment variables. If these changes are made, then the environment variables could be removed.
62
+ It skips any environment variables that are used for secrets.
63
+ DOC
64
+ task env_vars_without_default: :environment do
65
+ require_relative "utils"
66
+ require_relative "../audit_data_sources"
67
+
68
+ UltraSettings::Tasks::Utils.eager_load!
69
+ env_vars_without_default = UltraSettings::AuditDataSources.env_vars_without_default
70
+
71
+ output = env_vars_without_default.collect do |config, field, env_var, value|
72
+ "Environment variable #{env_var} used by #{config}##{field} does not have a default value (current value: #{value.inspect})"
73
+ end
74
+ puts output
75
+ end
76
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UltraSettings
4
+ module Tasks
5
+ module Utils
6
+ class << self
7
+ # Helper for eager loading a Rails application.
8
+ def eager_load!
9
+ return unless defined?(Rails.application.config.eager_load)
10
+ return if Rails.application.config.eager_load
11
+
12
+ if defined?(Rails.application.eager_load!)
13
+ Rails.application.eager_load!
14
+ elsif defined?(Rails.autoloaders.zeitwerk_enabled?) && Rails.autoloaders.zeitwerk_enabled?
15
+ Rails.autoloaders.each(&:eager_load)
16
+ else
17
+ raise "Failed to eager load application."
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -11,6 +11,7 @@ module UltraSettings
11
11
  # @param path [String] The path to the template file.
12
12
  # @return [ERB] The compiled ERB template.
13
13
  def erb_template(path)
14
+ @cache.clear if development_mode?
14
15
  @cache["erb:#{path}"] ||= ERB.new(read_app_file(path))
15
16
  end
16
17
 
@@ -19,6 +20,7 @@ module UltraSettings
19
20
  # @param path [String] The path to the file relative to the app directory.
20
21
  # @return [String] The contents of the file.
21
22
  def read_app_file(path)
23
+ @cache.clear if development_mode?
22
24
  @cache["file:#{path}"] ||= File.read(File.join(app_dir, path))
23
25
  end
24
26
 
@@ -28,6 +30,12 @@ module UltraSettings
28
30
  def app_dir
29
31
  File.expand_path(File.join("..", "..", "app"), __dir__)
30
32
  end
33
+
34
+ private
35
+
36
+ def development_mode?
37
+ ENV.fetch("RACK_ENV", "development") == "development"
38
+ end
31
39
  end
32
40
  end
33
41
  end
@@ -14,6 +14,7 @@ require_relative "ultra_settings/config_helper"
14
14
  require_relative "ultra_settings/field"
15
15
  require_relative "ultra_settings/rack_app"
16
16
  require_relative "ultra_settings/view_helper"
17
+ require_relative "ultra_settings/render_helper"
17
18
  require_relative "ultra_settings/web_view"
18
19
  require_relative "ultra_settings/application_view"
19
20
  require_relative "ultra_settings/configuration_view"
@@ -259,6 +260,19 @@ module UltraSettings
259
260
  @configurations.keys
260
261
  end
261
262
 
263
+ # Get an array of all of the configuration instances that have been loaded into memory.
264
+ #
265
+ # @return [Array<UltraSettings::Configuration>] The configuration instances.
266
+ # @api private
267
+ def __configurations__
268
+ @configurations.each do |name, class_name|
269
+ __load_config__(name, class_name)
270
+ end
271
+
272
+ config_classes = ObjectSpace.each_object(Class).select { |klass| klass < Configuration }
273
+ config_classes.collect(&:instance)
274
+ end
275
+
262
276
  private
263
277
 
264
278
  # Load a configuration class.
@@ -28,6 +28,8 @@ Gem::Specification.new do |spec|
28
28
  bin/
29
29
  gemfiles/
30
30
  spec/
31
+ test_app/
32
+ yard_plugin/
31
33
  ]
32
34
  spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
33
35
  `git ls-files -z`.split("\x0").reject { |f| ignore_files.any? { |path| f.start_with?(path) } }
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultra_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-09-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -24,18 +23,22 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '0'
27
- description:
28
26
  email:
29
27
  - bbdurand@gmail.com
30
28
  executables: []
31
29
  extensions: []
32
30
  extra_rdoc_files: []
33
31
  files:
32
+ - AGENTS.md
34
33
  - ARCHITECTURE.md
35
34
  - CHANGELOG.md
36
35
  - MIT-LICENSE.txt
37
36
  - README.md
38
37
  - VERSION
38
+ - app/_config_description.html.erb
39
+ - app/_config_list.html.erb
40
+ - app/_data_source.html.erb
41
+ - app/_select_menu.html.erb
39
42
  - app/application.css
40
43
  - app/application.js
41
44
  - app/application_vars.css.erb
@@ -46,6 +49,7 @@ files:
46
49
  - app/layout_vars.css.erb
47
50
  - lib/ultra_settings.rb
48
51
  - lib/ultra_settings/application_view.rb
52
+ - lib/ultra_settings/audit_data_sources.rb
49
53
  - lib/ultra_settings/coerce.rb
50
54
  - lib/ultra_settings/config_helper.rb
51
55
  - lib/ultra_settings/configuration.rb
@@ -53,6 +57,9 @@ files:
53
57
  - lib/ultra_settings/field.rb
54
58
  - lib/ultra_settings/rack_app.rb
55
59
  - lib/ultra_settings/railtie.rb
60
+ - lib/ultra_settings/render_helper.rb
61
+ - lib/ultra_settings/tasks/audit_data_sources.rake
62
+ - lib/ultra_settings/tasks/utils.rb
56
63
  - lib/ultra_settings/uninitialized_runtime_settings.rb
57
64
  - lib/ultra_settings/version.rb
58
65
  - lib/ultra_settings/view_helper.rb
@@ -66,7 +73,6 @@ metadata:
66
73
  homepage_uri: https://github.com/bdurand/ultra_settings
67
74
  source_code_uri: https://github.com/bdurand/ultra_settings
68
75
  changelog_uri: https://github.com/bdurand/ultra_settings/blob/main/CHANGELOG.md
69
- post_install_message:
70
76
  rdoc_options: []
71
77
  require_paths:
72
78
  - lib
@@ -81,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
87
  - !ruby/object:Gem::Version
82
88
  version: '0'
83
89
  requirements: []
84
- rubygems_version: 3.4.10
85
- signing_key:
90
+ rubygems_version: 4.0.3
86
91
  specification_version: 4
87
92
  summary: UltraSettings is a Ruby gem that provides a flexible and documented approach
88
93
  to managing application configurations from multiple sources, including environment