anyway_config 2.5.2 → 2.5.4

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: 3c4d3be4fe0dc48b125dc8eb14be21611e1c9a356953f2a2bdad1444aa21eabe
4
- data.tar.gz: 4796c3d47f70459e0732913997c9fa80ce5a0a604cb86d8d3098a9144a692326
3
+ metadata.gz: ecd889b5a9f662d00312e10d8bb01c25f35cfe56aa1f4e361fee46ead43af918
4
+ data.tar.gz: 5c3921ddef8bbef598806a55f8f8beb9bf7b27b49df296bf1dc168370a4c159f
5
5
  SHA512:
6
- metadata.gz: 7892284a2c1f50287dada83b90be86b11c557a0ec5e5d457a672d9d1db6ba6603299cf5060ca2134dc391f2aa02e3f17f8bcd221b0e8473a55dc99e0bea06ec8
7
- data.tar.gz: f4f276d19c6a8a25ebcf46c1e55f176070691fa7af76b15bebafdf9b36a5716e7c3e1fb5ddcba2d07e741792eff0ed46d373d2b5651ac77c58d0b4527a097e75
6
+ metadata.gz: 5e9911f756c77a8110b031a8afef85819915742fe541f9bbfcd58011c6cb4f05f65928da4bed158f82a52fa9ad41c76420d3ad3f9885d2c4c7bd3aeb6307b849
7
+ data.tar.gz: a6aa11ab9a3681983df6ce936680511fc9cc86658287ff7a3ff5691201d83e85cbac9b18155a04cb8bbccd81f41fdd0cabe203504c11a5baab2afc0b831a470e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 2.5.4 (2023-10-15)
6
+
7
+ - Fix tracing with empty config keys. ([@palkan][])
8
+
9
+ ## 2.5.3 (2023-09-12)
10
+
11
+ - Do not activate Rails secrets loaders in 7.1+. ([@palkan][])
12
+
13
+ - Set `use_local_files` depending on `Rails.env`. ([@marshall-lee][])
14
+
5
15
  ## 2.5.2 (2023-08-23)
6
16
 
7
17
  - Disable Rails post-load detection in TruffleRuby. ([@palkan][])
data/README.md CHANGED
@@ -434,7 +434,7 @@ config.anyway_config.default_config_path = ->(name) { Rails.root.join("data", "c
434
434
 
435
435
  - By overriding a specific config YML file path via the `<NAME>_CONF` env variable, e.g., `MYCOOLGEM_CONF=path/to/cool.yml`
436
436
 
437
- 2) **Rails secrets**: `Rails.application.secrets.my_cool_gem` (if `secrets.yml` present).
437
+ 2) (Rails <7.1) **Rails secrets**: `Rails.application.secrets.my_cool_gem` (if `secrets.yml` present).
438
438
 
439
439
  ```yml
440
440
  # config/secrets.yml
@@ -443,6 +443,8 @@ development:
443
443
  port: 4444
444
444
  ```
445
445
 
446
+ **NOTE:** If you want to use secrets with Rails 7.1 (still supported, but deprecated) you must add the corresponding loader manually: `Anyway.loaders.insert_after :yml, :secrets, Anyway::Rails::Loaders::Secrets`.
447
+
446
448
  3) **Rails credentials**: `Rails.application.credentials.my_cool_gem` (if supported):
447
449
 
448
450
  ```yml
@@ -848,11 +850,17 @@ You can use `Anyway::Loaders::Base` as a base class for your loader and define a
848
850
  For example, the [Chamber](https://github.com/thekompanee/chamber) loader could be written as follows:
849
851
 
850
852
  ```ruby
851
- class ChamberConfigLoader < Anyway::Loaders::Base
853
+ class ChamberConfigLoader < Base
852
854
  def call(name:, **_opts)
853
- Chamber.env.to_h[name] || {}
855
+ Chamber.to_hash[name] || {}
856
+ rescue Chamber::Errors::DecryptionFailure => e
857
+ warn "Couldn't decrypt Chamber settings: #{e.message}"
858
+ {}
854
859
  end
855
860
  end
861
+
862
+ # Don't forget to register it
863
+ Anyway.loaders.insert_before :env, :chamber, ChamberConfigLoader
856
864
  ```
857
865
 
858
866
  In order to support [source tracing](#tracing), you need to wrap the resulting Hash via the `#trace!` method with metadata:
@@ -860,7 +868,10 @@ In order to support [source tracing](#tracing), you need to wrap the resulting H
860
868
  ```ruby
861
869
  def call(name:, **_opts)
862
870
  trace!(:chamber) do
863
- Chamber.env.to_h[name] || {}
871
+ Chamber.to_hash[name] || {}
872
+ rescue Chamber::Errors::DecryptionFailure => e
873
+ warn "Couldn't decrypt Chamber settings: #{e.message}"
874
+ {}
864
875
  end
865
876
  end
866
877
  ```
@@ -217,7 +217,8 @@ module Anyway # :nodoc:
217
217
  Utils.deep_merge!(coercion_mapping, mapping)
218
218
 
219
219
  mapping.each do |key, val|
220
- next unless val == :boolean || (val.is_a?(::Hash) && val[:type] == :boolean)
220
+ type = val.is_a?(::Hash) ? val[:type] : val
221
+ next if type != :boolean
221
222
 
222
223
  alias_method :"#{key}?", :"#{key}"
223
224
  end
@@ -100,7 +100,7 @@ module Anyway
100
100
  self.current_environment = ENV["ANYWAY_ENV"]
101
101
 
102
102
  # By default, use local files only in development (that's the purpose if the local files)
103
- self.use_local_files = (ENV["ANYWAY_ENV"] == "development" || ENV["RACK_ENV"] == "development" || ENV["RAILS_ENV"] == "development")
103
+ self.use_local_files = (ENV["ANYWAY_ENV"] == "development" || ENV["RACK_ENV"] == "development" || ENV["RAILS_ENV"] == "development" || (defined?(Rails) && Rails.env.development?))
104
104
 
105
105
  # By default, consider configs are stored in the ./config folder
106
106
  self.default_config_path = ->(name) { "./config/#{name}.yml" }
@@ -179,7 +179,7 @@ module Anyway
179
179
  val = yield
180
180
  if val.is_a?(Hash)
181
181
  Tracing.current_trace.merge_values(val, type: type, **opts)
182
- else
182
+ elsif !path.empty?
183
183
  Tracing.current_trace.record_value(val, *path, type: type, **opts)
184
184
  end
185
185
  val
@@ -217,7 +217,8 @@ module Anyway # :nodoc:
217
217
  Utils.deep_merge!(coercion_mapping, mapping)
218
218
 
219
219
  mapping.each do |key, val|
220
- next unless val == :boolean || (val.is_a?(::Hash) && val[:type] == :boolean)
220
+ type = val.is_a?(::Hash) ? val[:type] : val
221
+ next if type != :boolean
221
222
 
222
223
  alias_method :"#{key}?", :"#{key}"
223
224
  end
@@ -179,7 +179,7 @@ module Anyway
179
179
  val = yield
180
180
  if val.is_a?(Hash)
181
181
  Tracing.current_trace.merge_values(val, type: type, **opts)
182
- else
182
+ elsif !path.empty?
183
183
  Tracing.current_trace.record_value(val, *path, type: type, **opts)
184
184
  end
185
185
  val
@@ -217,7 +217,8 @@ module Anyway # :nodoc:
217
217
  Utils.deep_merge!(coercion_mapping, mapping)
218
218
 
219
219
  mapping.each do |key, val|
220
- next unless val == :boolean || (val.is_a?(::Hash) && val[:type] == :boolean)
220
+ type = val.is_a?(::Hash) ? val[:type] : val
221
+ next if type != :boolean
221
222
 
222
223
  alias_method :"#{key}?", :"#{key}"
223
224
  end
@@ -179,7 +179,7 @@ module Anyway
179
179
  val = yield
180
180
  if val.is_a?(Hash)
181
181
  Tracing.current_trace.merge_values(val, type: type, **opts)
182
- else
182
+ elsif !path.empty?
183
183
  Tracing.current_trace.record_value(val, *path, type: type, **opts)
184
184
  end
185
185
  val
data/lib/anyway/config.rb CHANGED
@@ -217,7 +217,8 @@ module Anyway # :nodoc:
217
217
  Utils.deep_merge!(coercion_mapping, mapping)
218
218
 
219
219
  mapping.each do |key, val|
220
- next unless val == :boolean || (val.is_a?(::Hash) && val[:type] == :boolean)
220
+ type = val.is_a?(::Hash) ? val[:type] : val
221
+ next if type != :boolean
221
222
 
222
223
  alias_method :"#{key}?", :"#{key}"
223
224
  end
data/lib/anyway/rails.rb CHANGED
@@ -11,8 +11,13 @@ require "anyway/rails/loaders"
11
11
 
12
12
  # Configure Rails loaders
13
13
  Anyway.loaders.override :yml, Anyway::Rails::Loaders::YAML
14
- Anyway.loaders.insert_after :yml, :secrets, Anyway::Rails::Loaders::Secrets
15
- Anyway.loaders.insert_after :secrets, :credentials, Anyway::Rails::Loaders::Credentials
14
+
15
+ if Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 1
16
+ Anyway.loaders.insert_after :yml, :credentials, Anyway::Rails::Loaders::Credentials
17
+ else
18
+ Anyway.loaders.insert_after :yml, :secrets, Anyway::Rails::Loaders::Secrets
19
+ Anyway.loaders.insert_after :secrets, :credentials, Anyway::Rails::Loaders::Credentials
20
+ end
16
21
 
17
22
  # Load Railties after configuring loaders.
18
23
  # The application could be already initialized, and that would make `Anyway.loaders` frozen
@@ -100,7 +100,7 @@ module Anyway
100
100
  self.current_environment = ENV["ANYWAY_ENV"]
101
101
 
102
102
  # By default, use local files only in development (that's the purpose if the local files)
103
- self.use_local_files = (ENV["ANYWAY_ENV"] == "development" || ENV["RACK_ENV"] == "development" || ENV["RAILS_ENV"] == "development")
103
+ self.use_local_files = (ENV["ANYWAY_ENV"] == "development" || ENV["RACK_ENV"] == "development" || ENV["RAILS_ENV"] == "development" || (defined?(Rails) && Rails.env.development?))
104
104
 
105
105
  # By default, consider configs are stored in the ./config folder
106
106
  self.default_config_path = ->(name) { "./config/#{name}.yml" }
@@ -179,7 +179,7 @@ module Anyway
179
179
  val = yield
180
180
  if val.is_a?(Hash)
181
181
  Tracing.current_trace.merge_values(val, type:, **opts)
182
- else
182
+ elsif !path.empty?
183
183
  Tracing.current_trace.record_value(val, *path, type:, **opts)
184
184
  end
185
185
  val
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyway # :nodoc:
4
- VERSION = "2.5.2"
4
+ VERSION = "2.5.4"
5
5
  end
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.5.2
4
+ version: 2.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-23 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-next-core