anyway_config 2.6.4 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7cfb06bc950fa9f4c16b771509fc8e88cbe1481ea82a145c2fae80fca80b57b
4
- data.tar.gz: fdbd419a8ff57a7fbbb4e887381048e68d830d4927761ec420706e8add146e3a
3
+ metadata.gz: 2eb0c3ba37fd0260a03e8e5076df051f992c4911dab345158e761c06eebc8c11
4
+ data.tar.gz: 24b0f8193ade0506d71843ba3f7451cfab4bba806d856ea790a19c1ae3276c8d
5
5
  SHA512:
6
- metadata.gz: b7dd1abbf6411c416571ac67c127b0f0e365c73689d96d094289ab0ede4c494bd56f4246848431a689b2292a2903cea74b918e11569d89423c21e11f2dc3e9ca
7
- data.tar.gz: 4d8f2aecbbe6e79314a81d47f4fb92b3dcaba42a656387fbb24dd7c0dc051f3cae0b98de84f797cb48bc3fb9055bf59fd32c128ad4ee979e60eb3a71935a5e5a
6
+ metadata.gz: faea4614c6e0bf13982bfe3e0808be0d784a095be66b09dd283afd0d8e38d668b6e518bd5c19f1b7bc32252a1e3045595d91b24fc5c8094a1a03da20adf6faf7
7
+ data.tar.gz: 2b0cd4d3e551756bcb773782b105059a20224963bc91dc44557c35fd8c2edd745eb98d14a60668b557cbac9d3831c0195f56df9829a89f6c1cfadd949f1a07d7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 2.7.0 (2025-02-12)
6
+
7
+ - Added `suppress_required_validations` configuration for skipping validation in CI. ([@OlegChuev][])
8
+
9
+ - Support for the Rails built-in environment variable `SECRET_KEY_BASE_DUMMY`. If this variable is set, all validations for required attributes are skipped. This is particularly useful for executing `bundle exec rails assets:precompile` in CI/CD pipelines. ([@OlegChuev][])
10
+
11
+ - Introduced a global setting `Anyway::Settings.suppress_required_validations = true` to disable validations. This can be toggled via the environment variable `ANYWAY_SUPPRESS_VALIDATIONS`. Please note, `ANYWAY_SUPPRESS_VALIDATIONS` takes precedence over `SECRET_KEY_BASE_DUMMY`.
12
+
13
+ - Added `:integer!` type support (strong integer coercion). ([@klondaiker][])
14
+
15
+ - Fix handling relative vs. absolute paths in `autoload_static_configs_path=`. ([@palkan][])
16
+
17
+ - Fix support for array values in `except` option for required attributes. ([@dominikb][])
18
+
5
19
  ## 2.6.4 (2024-04-30)
6
20
 
7
21
  - Fix RBS manifest file name (`.yml` -> `.yaml`). ([@carlqt][])
@@ -579,3 +593,6 @@ No we're dependency-free!
579
593
  [@tagirahmad]: https://github.com/tagirahmad
580
594
  [@bessey]: https://github.com/bessey
581
595
  [@carlqt]: https://github.com/carlqt
596
+ [@OlegChuev]: https://github.com/OlegChuev
597
+ [@dominikb]: https://github.com/dominikb
598
+ [@klondaiker]: https://github.com/klondaiker
data/README.md CHANGED
@@ -73,7 +73,7 @@ end
73
73
 
74
74
  Using Ruby classes to represent configuration allows you to add helper methods and computed parameters easily, makes the configuration **testable**.
75
75
 
76
- The `anyway_config` gem takes care of loading parameters from **different sources** (YAML, credentials/secrets, environment variables, etc.). Internally, we use a _pipeline pattern_ and provide the [Loaders API](#data-loaders) to manage and [extend](#custom-loaders) its functionality.
76
+ The `anyway_config` gem takes care of loading parameters from **different sources** (YAML, credentials, environment variables, etc.). Internally, we use a _pipeline pattern_ and provide the [Loaders API](#data-loaders) to manage and [extend](#custom-loaders) its functionality.
77
77
 
78
78
  Check out the libraries using Anyway Config for more examples:
79
79
 
@@ -270,7 +270,6 @@ This feature is similar to `Rails.application.config_for` but more powerful:
270
270
  | Feature | Rails | Anyway Config |
271
271
  | ------------- |-------------:| -----:|
272
272
  | Load data from `config/app.yml` | ✅ | ✅ |
273
- | Load data from `secrets` | ❌ | ✅ |
274
273
  | Load data from `credentials` | ❌ | ✅ |
275
274
  | Load data from environment | ❌ | ✅ |
276
275
  | Load data from [other sources](#data-loaders) | ❌ | ✅ |
@@ -304,6 +303,9 @@ MyConfig.new(api_secret: "") #=> raises Anyway::Config::ValidationError
304
303
  `Required` method supports additional `env` parameter which indicates necessity to run validations under specified
305
304
  environments. `Env` parameter could be present in symbol, string, array or hash formats:
306
305
 
306
+ **NOTE:** You can suppress the validation of the required parameters (it can be useful for CI) via the `ANYWAY_SUPPRESS_VALIDATIONS` environment variable or by setting it explicitly in the code: `Anyway::Settings.suppress_required_validations = true`.
307
+ If you are using Anyway Config with Rails and have already specified `SECRET_KEY_BASE_DUMMY` for asset pre compilation, validation will be skipped by default.
308
+
307
309
  ```ruby
308
310
  class EnvConfig < Anyway::Config
309
311
  required :password, env: "production"
@@ -712,7 +714,7 @@ CoolConfig.new.port == "443" #=> true
712
714
 
713
715
  **IMPORTANT**: Values provided explicitly (via attribute writers) are not coerced. Coercion is only happening during the load phase.
714
716
 
715
- The following types are supported out-of-the-box: `:string`, `:integer`, `:float`, `:date`, `:datetime`, `:uri`, `:boolean`.
717
+ The following types are supported out-of-the-box: `:string`, `:integer`, `:integer!` (strict integer), `:float`, `:date`, `:datetime`, `:uri`, `:boolean`.
716
718
 
717
719
  You can use custom deserializers by passing a callable object instead of a type name:
718
720
 
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -52,6 +52,9 @@ module Anyway
52
52
  :default_environmental_key,
53
53
  :known_environments
54
54
 
55
+ # Suppress required validations for CI/CD pipelines
56
+ attr_accessor :suppress_required_validations
57
+
55
58
  # A proc returning a path to YML config file given the config name
56
59
  attr_reader :default_config_path
57
60
 
@@ -86,7 +89,7 @@ module Anyway
86
89
 
87
90
  if env.is_a?(::Hash)
88
91
  envs = env[:except]
89
- excluded_envs = [envs].flat_map(&:to_s)
92
+ excluded_envs = [*envs].flat_map(&:to_s)
90
93
  excluded_envs.none?(current_environment)
91
94
  elsif env.is_a?(::Array)
92
95
  env.flat_map(&:to_s).include?(current_environment)
@@ -107,5 +110,8 @@ module Anyway
107
110
 
108
111
  # Tracing is enabled by default
109
112
  self.tracing_enabled = true
113
+
114
+ # By default, use ANYWAY_SUPPRESS_VALIDATIONS
115
+ self.suppress_required_validations = %w[1 t true y yes].include?(ENV["ANYWAY_SUPPRESS_VALIDATIONS"])
110
116
  end
111
117
  end
@@ -88,6 +88,10 @@ module Anyway
88
88
  obj.accept(:boolean) do |_1|
89
89
  _1.to_s.match?(/\A(true|t|yes|y|1)\z/i)
90
90
  end
91
+
92
+ obj.accept(:integer!) do |_1|
93
+ Integer(_1)
94
+ end
91
95
  end
92
96
 
93
97
  unless "".respond_to?(:safe_constantize)
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -88,6 +88,10 @@ module Anyway
88
88
  obj.accept(:boolean) do
89
89
  _1.to_s.match?(/\A(true|t|yes|y|1)\z/i)
90
90
  end
91
+
92
+ obj.accept(:integer!) do
93
+ Integer(_1)
94
+ end
91
95
  end
92
96
 
93
97
  unless "".respond_to?(:safe_constantize)
data/lib/anyway/config.rb CHANGED
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -19,7 +19,7 @@ module Anyway
19
19
 
20
20
  return unless ::Rails.root.join(val).exist?
21
21
 
22
- return if val == autoload_static_config_path
22
+ return if ::Rails.root.join(val.to_s) == ::Rails.root.join(autoload_static_config_path.to_s)
23
23
 
24
24
  autoloader&.unload
25
25
 
@@ -79,5 +79,7 @@ module Anyway
79
79
  self.use_local_files ||= ::Rails.env.development?
80
80
  # Don't try read defaults when no key defined
81
81
  self.default_environmental_key = nil
82
+
83
+ self.suppress_required_validations = ENV.key?("SECRET_KEY_BASE_DUMMY") unless ENV.key?("ANYWAY_SUPPRESS_VALIDATIONS")
82
84
  end
83
85
  end
@@ -52,6 +52,9 @@ module Anyway
52
52
  :default_environmental_key,
53
53
  :known_environments
54
54
 
55
+ # Suppress required validations for CI/CD pipelines
56
+ attr_accessor :suppress_required_validations
57
+
55
58
  # A proc returning a path to YML config file given the config name
56
59
  attr_reader :default_config_path
57
60
 
@@ -86,7 +89,7 @@ module Anyway
86
89
 
87
90
  if env.is_a?(::Hash)
88
91
  envs = env[:except]
89
- excluded_envs = [envs].flat_map(&:to_s)
92
+ excluded_envs = [*envs].flat_map(&:to_s)
90
93
  excluded_envs.none?(current_environment)
91
94
  elsif env.is_a?(::Array)
92
95
  env.flat_map(&:to_s).include?(current_environment)
@@ -107,5 +110,8 @@ module Anyway
107
110
 
108
111
  # Tracing is enabled by default
109
112
  self.tracing_enabled = true
113
+
114
+ # By default, use ANYWAY_SUPPRESS_VALIDATIONS
115
+ self.suppress_required_validations = %w[1 t true y yes].include?(ENV["ANYWAY_SUPPRESS_VALIDATIONS"])
110
116
  end
111
117
  end
@@ -88,6 +88,10 @@ module Anyway
88
88
  obj.accept(:boolean) do
89
89
  _1.to_s.match?(/\A(true|t|yes|y|1)\z/i)
90
90
  end
91
+
92
+ obj.accept(:integer!) do
93
+ Integer(_1)
94
+ end
91
95
  end
92
96
 
93
97
  unless "".respond_to?(:safe_constantize)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyway # :nodoc:
4
- VERSION = "2.6.4"
4
+ VERSION = "2.7.0"
5
5
  end
@@ -7,6 +7,7 @@ module Anyway
7
7
  def self.future: -> Future
8
8
  def self.current_environment: -> String?
9
9
  def self.default_environmental_key: -> String?
10
+ def self.suppress_required_validations: -> bool
10
11
  def self.known_environments: -> Array[String]?
11
12
 
12
13
  class Future
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anyway_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.4
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-30 00:00:00.000000000 Z
11
+ date: 2025-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-next-core
@@ -206,7 +206,7 @@ metadata:
206
206
  homepage_uri: http://github.com/palkan/anyway_config
207
207
  source_code_uri: http://github.com/palkan/anyway_config
208
208
  funding_uri: https://github.com/sponsors/palkan
209
- post_install_message:
209
+ post_install_message:
210
210
  rdoc_options: []
211
211
  require_paths:
212
212
  - lib
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  version: '0'
223
223
  requirements: []
224
224
  rubygems_version: 3.4.19
225
- signing_key:
225
+ signing_key:
226
226
  specification_version: 4
227
227
  summary: Configuration DSL for Ruby libraries and applications
228
228
  test_files: []