anyway_config 2.7.2 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +23 -5
- data/lib/.rbnext/2.7/anyway/loaders/yaml.rb +0 -1
- data/lib/.rbnext/2.7/anyway/tracing.rb +2 -2
- data/lib/.rbnext/2.7/anyway/type_casting.rb +1 -1
- data/lib/.rbnext/3.0/anyway/auto_cast.rb +2 -2
- data/lib/.rbnext/3.0/anyway/config.rb +16 -5
- data/lib/.rbnext/3.0/anyway/loaders/yaml.rb +0 -1
- data/lib/.rbnext/3.0/anyway/loaders.rb +9 -8
- data/lib/.rbnext/3.0/anyway/tracing.rb +2 -2
- data/lib/.rbnext/3.1/anyway/config.rb +16 -5
- data/lib/.rbnext/3.1/anyway/env.rb +0 -1
- data/lib/.rbnext/3.1/anyway/tracing.rb +2 -2
- data/lib/.rbnext/3.2/anyway/config.rb +16 -5
- data/lib/.rbnext/3.2/anyway/tracing.rb +2 -2
- data/lib/.rbnext/3.4/anyway/auto_cast.rb +2 -2
- data/lib/.rbnext/3.4/anyway/config.rb +16 -5
- data/lib/.rbnext/3.4/anyway/tracing.rb +2 -2
- data/lib/.rbnext/3.4/anyway/type_casting.rb +1 -1
- data/lib/anyway/config.rb +14 -3
- data/lib/anyway/env.rb +0 -1
- data/lib/anyway/loaders/doppler.rb +0 -2
- data/lib/anyway/loaders/env.rb +0 -2
- data/lib/anyway/loaders/yaml.rb +0 -1
- data/lib/anyway/loaders.rb +9 -8
- data/lib/anyway/option_parser_builder.rb +1 -1
- data/lib/anyway/rails/autoload.rb +0 -2
- data/lib/anyway/rails/loaders/credentials.rb +0 -2
- data/lib/anyway/rails/loaders/secrets.rb +0 -2
- data/lib/anyway/rails/settings.rb +2 -0
- data/lib/anyway/utils/which.rb +2 -1
- data/lib/anyway/version.rb +1 -1
- data/lib/anyway_config.rb +8 -3
- data/sig/anyway_config.rbs +3 -0
- metadata +3 -5
- data/lib/.rbnext/2.7/anyway/auto_cast.rb +0 -53
- data/lib/.rbnext/2.7/anyway/config.rb +0 -475
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c2505731c8729ea6a097cef8718c441684124da047a6856bd6156b4592c1ad9b
|
|
4
|
+
data.tar.gz: d20b15281220f9c3d77b7440ffcf915db6b28e6c7555ecec5ac9e4583de34887
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70db78ae8a9859a4f660173101127d4e8d30c6a059f5b3cba121864be120a787a5998f740a948651f84c82cb22e87f7bce7926a4ad6b27352297dbc9f24d20b4
|
|
7
|
+
data.tar.gz: a314943f0a1fe0779235a75656d80cbf7a1525bbd6db24ab4fe15f508d4ac3c2790819a6d9abf39682c17c0bb0fadf4184976e9a9753dc3d61f594b910bd211a
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## master
|
|
4
4
|
|
|
5
|
+
## 2.8.1 (2026-07-22)
|
|
6
|
+
|
|
7
|
+
- Fix default loaders order to keep ENV the last one (=higher precedence). ([@palkan][])
|
|
8
|
+
|
|
9
|
+
- Guard against a missing `PATH` environment variable in `Anyway::Utils.which`. ([@SAY-5][])
|
|
10
|
+
|
|
11
|
+
- Do not require optional loader dependencies to speed up loading. ([@ardecvz][])
|
|
12
|
+
|
|
13
|
+
## 2.8.0 (2026-06-24)
|
|
14
|
+
|
|
15
|
+
- Add `configuration_sources` option to config classes to specify which data sources to use. ([@palkan][])
|
|
16
|
+
|
|
5
17
|
## 2.7.2 (2025-04-01)
|
|
6
18
|
|
|
7
19
|
- Address NameError: instance variable @secrets not defined issue ([@fbuys][])
|
|
@@ -604,3 +616,5 @@ No we're dependency-free!
|
|
|
604
616
|
[@OlegChuev]: https://github.com/OlegChuev
|
|
605
617
|
[@dominikb]: https://github.com/dominikb
|
|
606
618
|
[@klondaiker]: https://github.com/klondaiker
|
|
619
|
+
[@ardecvz]: https://github.com/ardecvz
|
|
620
|
+
[@SAY-5]: https://github.com/SAY-5
|
data/README.md
CHANGED
|
@@ -105,8 +105,8 @@ gem "anyway_config", "~> 2.0"
|
|
|
105
105
|
|
|
106
106
|
### Supported Ruby versions
|
|
107
107
|
|
|
108
|
-
- Ruby (MRI) >= 2.
|
|
109
|
-
- JRuby >= 9.
|
|
108
|
+
- Ruby (MRI) >= 2.7.0
|
|
109
|
+
- JRuby >= 9.3.0
|
|
110
110
|
|
|
111
111
|
## Usage
|
|
112
112
|
|
|
@@ -347,7 +347,7 @@ end
|
|
|
347
347
|
|
|
348
348
|
## Using with Rails
|
|
349
349
|
|
|
350
|
-
**NOTE:** version 2.x supports Rails >=
|
|
350
|
+
**NOTE:** version 2.x supports Rails >= 6.0; for older versions use version 1.x of the gem.
|
|
351
351
|
|
|
352
352
|
We recommend going through [Data population](#data-population) and [Organizing configs](#organizing-configs) sections first,
|
|
353
353
|
and then use [Rails generators](#generators) to make your application Anyway Config-ready.
|
|
@@ -653,8 +653,6 @@ MYCOOLGEM = "Nif-Nif, Naf-Naf and Nouf-Nouf"
|
|
|
653
653
|
|
|
654
654
|
## Type coercion
|
|
655
655
|
|
|
656
|
-
> 🆕 v2.2.0
|
|
657
|
-
|
|
658
656
|
You can define custom type coercion rules to convert string data to config values. To do that, use `.coerce_types` method:
|
|
659
657
|
|
|
660
658
|
```ruby
|
|
@@ -827,6 +825,8 @@ class MyConfig < Anyway::Config
|
|
|
827
825
|
end
|
|
828
826
|
```
|
|
829
827
|
|
|
828
|
+
**NOTE:** You can opt-out from EJSON loader by specifying the `ANYWAY_CONFIG_DISABLE_EJSON=true` env var (in case you have the `ejson` executable in your PATH, but don't want to use it with Anyway Config).
|
|
829
|
+
|
|
830
830
|
### Custom loaders
|
|
831
831
|
|
|
832
832
|
You can provide your own data loaders or change the existing ones using the Loaders API (which is very similar to Rack middleware builder):
|
|
@@ -884,6 +884,24 @@ def call(name:, **_opts)
|
|
|
884
884
|
end
|
|
885
885
|
```
|
|
886
886
|
|
|
887
|
+
### Specifying which loaders to use
|
|
888
|
+
|
|
889
|
+
Sometimes you may want to pick only specific loaders for a particular configuration class. For that, you can use the `.configuration_sources=` writer method:
|
|
890
|
+
|
|
891
|
+
```ruby
|
|
892
|
+
class MyConfig < Anyway::Config
|
|
893
|
+
# Only load configuraiton data from ENV and credentials
|
|
894
|
+
self.configuration_sources = [:env, :credentials]
|
|
895
|
+
# ...
|
|
896
|
+
end
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
You can access the list of available loader identifiers as follows:
|
|
900
|
+
|
|
901
|
+
```ruby
|
|
902
|
+
Anyway.loaders.keys #=> [:yml, :credentials, :env]
|
|
903
|
+
```
|
|
904
|
+
|
|
887
905
|
## Tracing
|
|
888
906
|
|
|
889
907
|
Since Anyway Config loads data from multiple source, it could be useful to know where a particular value came from.
|
|
@@ -29,7 +29,7 @@ module Anyway
|
|
|
29
29
|
def record_value(val, *path, **opts)
|
|
30
30
|
key = path.pop
|
|
31
31
|
trace = if val.is_a?(Hash)
|
|
32
|
-
Trace.new.tap { |
|
|
32
|
+
Trace.new.tap { |it| it.merge_values(val, **opts) }
|
|
33
33
|
else
|
|
34
34
|
Trace.new(:value, val, **opts)
|
|
35
35
|
end
|
|
@@ -84,7 +84,7 @@ module Anyway
|
|
|
84
84
|
|
|
85
85
|
def to_h
|
|
86
86
|
if trace?
|
|
87
|
-
value.transform_values(&:to_h).tap { |
|
|
87
|
+
value.transform_values(&:to_h).tap { |it| it.default_proc = nil }
|
|
88
88
|
else
|
|
89
89
|
{value: value, source: source}
|
|
90
90
|
end
|
|
@@ -13,9 +13,9 @@ module Anyway
|
|
|
13
13
|
|
|
14
14
|
case val
|
|
15
15
|
when Hash
|
|
16
|
-
val.transform_values { it
|
|
16
|
+
val.transform_values { |it| call(it) }
|
|
17
17
|
when ARRAY_RXP
|
|
18
|
-
val.split(/\s*,\s*/).map { it
|
|
18
|
+
val.split(/\s*,\s*/).map { |it| call(it) }
|
|
19
19
|
when /\A(true|t|yes|y)\z/i
|
|
20
20
|
true
|
|
21
21
|
when /\A(false|f|no|n)\z/i
|
|
@@ -4,7 +4,6 @@ require "anyway/optparse_config"
|
|
|
4
4
|
require "anyway/dynamic_config"
|
|
5
5
|
|
|
6
6
|
module Anyway # :nodoc:
|
|
7
|
-
using RubyNext
|
|
8
7
|
using Anyway::Ext::DeepDup
|
|
9
8
|
using Anyway::Ext::DeepFreeze
|
|
10
9
|
using Anyway::Ext::Hash
|
|
@@ -93,7 +92,7 @@ module Anyway # :nodoc:
|
|
|
93
92
|
|
|
94
93
|
unless (reserved_names = (new_keys & RESERVED_NAMES)).empty?
|
|
95
94
|
raise ArgumentError, "Can not use the following reserved names as config attrubutes: " \
|
|
96
|
-
"#{reserved_names.sort.
|
|
95
|
+
"#{reserved_names.sort.join(", ")}"
|
|
97
96
|
end
|
|
98
97
|
|
|
99
98
|
config_attributes.push(*new_keys)
|
|
@@ -154,7 +153,7 @@ module Anyway # :nodoc:
|
|
|
154
153
|
if block
|
|
155
154
|
load_callbacks << BlockCallback.new(block)
|
|
156
155
|
else
|
|
157
|
-
load_callbacks.push(*names.map { it
|
|
156
|
+
load_callbacks.push(*names.map { |it| NamedCallback.new(it) })
|
|
158
157
|
end
|
|
159
158
|
end
|
|
160
159
|
|
|
@@ -261,6 +260,15 @@ module Anyway # :nodoc:
|
|
|
261
260
|
@fallback_type_caster = ::Anyway::NoCast
|
|
262
261
|
end
|
|
263
262
|
|
|
263
|
+
def configuration_sources
|
|
264
|
+
return @configuration_sources if instance_variable_defined?(:@configuration_sources)
|
|
265
|
+
return @configuration_sources = superclass.configuration_sources.dup if superclass.respond_to?(:configuration_sources)
|
|
266
|
+
|
|
267
|
+
@configuration_sources = nil
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
attr_writer :configuration_sources
|
|
271
|
+
|
|
264
272
|
private
|
|
265
273
|
|
|
266
274
|
def define_config_accessor(*names)
|
|
@@ -380,7 +388,7 @@ module Anyway # :nodoc:
|
|
|
380
388
|
trace&.keep_if { |key| self.class.config_attributes.include?(key.to_sym) }
|
|
381
389
|
|
|
382
390
|
# Run on_load callbacks
|
|
383
|
-
self.class.load_callbacks.each { it
|
|
391
|
+
self.class.load_callbacks.each { |it| it.apply_to(self) }
|
|
384
392
|
|
|
385
393
|
# Set trace after we write all the values to
|
|
386
394
|
# avoid changing the source to accessor
|
|
@@ -390,7 +398,10 @@ module Anyway # :nodoc:
|
|
|
390
398
|
end
|
|
391
399
|
|
|
392
400
|
def load_from_sources(base_config, **opts)
|
|
393
|
-
|
|
401
|
+
source_filter = self.class.configuration_sources
|
|
402
|
+
|
|
403
|
+
Anyway.loaders.each do |(id, loader)|
|
|
404
|
+
next if source_filter && !source_filter.include?(id)
|
|
394
405
|
Utils.deep_merge!(base_config, loader.call(**opts))
|
|
395
406
|
end
|
|
396
407
|
base_config
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
using RubyNext
|
|
3
|
+
require "anyway/loaders/base"
|
|
5
4
|
|
|
5
|
+
module Anyway
|
|
6
6
|
module Loaders
|
|
7
|
+
autoload :YAML, "anyway/loaders/yaml"
|
|
8
|
+
autoload :Env, "anyway/loaders/env"
|
|
9
|
+
autoload :EJSON, "anyway/loaders/ejson"
|
|
10
|
+
autoload :Doppler, "anyway/loaders/doppler"
|
|
11
|
+
|
|
7
12
|
class Registry
|
|
8
13
|
attr_reader :registry
|
|
9
14
|
|
|
@@ -55,6 +60,8 @@ module Anyway
|
|
|
55
60
|
registry.each(&block)
|
|
56
61
|
end
|
|
57
62
|
|
|
63
|
+
def keys() ; registry.map(&:first); end
|
|
64
|
+
|
|
58
65
|
def freeze() ; registry.freeze; end
|
|
59
66
|
|
|
60
67
|
private
|
|
@@ -71,9 +78,3 @@ module Anyway
|
|
|
71
78
|
end
|
|
72
79
|
end
|
|
73
80
|
end
|
|
74
|
-
|
|
75
|
-
require "anyway/loaders/base"
|
|
76
|
-
require "anyway/loaders/yaml"
|
|
77
|
-
require "anyway/loaders/env"
|
|
78
|
-
require "anyway/loaders/doppler"
|
|
79
|
-
require "anyway/loaders/ejson"
|
|
@@ -29,7 +29,7 @@ module Anyway
|
|
|
29
29
|
def record_value(val, *path, **opts)
|
|
30
30
|
key = path.pop
|
|
31
31
|
trace = if val.is_a?(Hash)
|
|
32
|
-
Trace.new.tap { it
|
|
32
|
+
Trace.new.tap { |it| it.merge_values(val, **opts) }
|
|
33
33
|
else
|
|
34
34
|
Trace.new(:value, val, **opts)
|
|
35
35
|
end
|
|
@@ -84,7 +84,7 @@ module Anyway
|
|
|
84
84
|
|
|
85
85
|
def to_h
|
|
86
86
|
if trace?
|
|
87
|
-
value.transform_values(&:to_h).tap { it
|
|
87
|
+
value.transform_values(&:to_h).tap { |it| it.default_proc = nil }
|
|
88
88
|
else
|
|
89
89
|
{value: value, source: source}
|
|
90
90
|
end
|
|
@@ -4,7 +4,6 @@ require "anyway/optparse_config"
|
|
|
4
4
|
require "anyway/dynamic_config"
|
|
5
5
|
|
|
6
6
|
module Anyway # :nodoc:
|
|
7
|
-
using RubyNext
|
|
8
7
|
using Anyway::Ext::DeepDup
|
|
9
8
|
using Anyway::Ext::DeepFreeze
|
|
10
9
|
using Anyway::Ext::Hash
|
|
@@ -93,7 +92,7 @@ module Anyway # :nodoc:
|
|
|
93
92
|
|
|
94
93
|
unless (reserved_names = (new_keys & RESERVED_NAMES)).empty?
|
|
95
94
|
raise ArgumentError, "Can not use the following reserved names as config attrubutes: " \
|
|
96
|
-
"#{reserved_names.sort.
|
|
95
|
+
"#{reserved_names.sort.join(", ")}"
|
|
97
96
|
end
|
|
98
97
|
|
|
99
98
|
config_attributes.push(*new_keys)
|
|
@@ -154,7 +153,7 @@ module Anyway # :nodoc:
|
|
|
154
153
|
if block
|
|
155
154
|
load_callbacks << BlockCallback.new(block)
|
|
156
155
|
else
|
|
157
|
-
load_callbacks.push(*names.map { it
|
|
156
|
+
load_callbacks.push(*names.map { |it| NamedCallback.new(it) })
|
|
158
157
|
end
|
|
159
158
|
end
|
|
160
159
|
|
|
@@ -261,6 +260,15 @@ module Anyway # :nodoc:
|
|
|
261
260
|
@fallback_type_caster = ::Anyway::NoCast
|
|
262
261
|
end
|
|
263
262
|
|
|
263
|
+
def configuration_sources
|
|
264
|
+
return @configuration_sources if instance_variable_defined?(:@configuration_sources)
|
|
265
|
+
return @configuration_sources = superclass.configuration_sources.dup if superclass.respond_to?(:configuration_sources)
|
|
266
|
+
|
|
267
|
+
@configuration_sources = nil
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
attr_writer :configuration_sources
|
|
271
|
+
|
|
264
272
|
private
|
|
265
273
|
|
|
266
274
|
def define_config_accessor(*names)
|
|
@@ -380,7 +388,7 @@ module Anyway # :nodoc:
|
|
|
380
388
|
trace&.keep_if { |key| self.class.config_attributes.include?(key.to_sym) }
|
|
381
389
|
|
|
382
390
|
# Run on_load callbacks
|
|
383
|
-
self.class.load_callbacks.each { it
|
|
391
|
+
self.class.load_callbacks.each { |it| it.apply_to(self) }
|
|
384
392
|
|
|
385
393
|
# Set trace after we write all the values to
|
|
386
394
|
# avoid changing the source to accessor
|
|
@@ -390,7 +398,10 @@ module Anyway # :nodoc:
|
|
|
390
398
|
end
|
|
391
399
|
|
|
392
400
|
def load_from_sources(base_config, **opts)
|
|
393
|
-
|
|
401
|
+
source_filter = self.class.configuration_sources
|
|
402
|
+
|
|
403
|
+
Anyway.loaders.each do |(id, loader)|
|
|
404
|
+
next if source_filter && !source_filter.include?(id)
|
|
394
405
|
Utils.deep_merge!(base_config, loader.call(**opts))
|
|
395
406
|
end
|
|
396
407
|
base_config
|
|
@@ -29,7 +29,7 @@ module Anyway
|
|
|
29
29
|
def record_value(val, *path, **opts)
|
|
30
30
|
key = path.pop
|
|
31
31
|
trace = if val.is_a?(Hash)
|
|
32
|
-
Trace.new.tap { it
|
|
32
|
+
Trace.new.tap { |it| it.merge_values(val, **opts) }
|
|
33
33
|
else
|
|
34
34
|
Trace.new(:value, val, **opts)
|
|
35
35
|
end
|
|
@@ -84,7 +84,7 @@ module Anyway
|
|
|
84
84
|
|
|
85
85
|
def to_h
|
|
86
86
|
if trace?
|
|
87
|
-
value.transform_values(&:to_h).tap { it
|
|
87
|
+
value.transform_values(&:to_h).tap { |it| it.default_proc = nil }
|
|
88
88
|
else
|
|
89
89
|
{value: value, source: source}
|
|
90
90
|
end
|
|
@@ -4,7 +4,6 @@ require "anyway/optparse_config"
|
|
|
4
4
|
require "anyway/dynamic_config"
|
|
5
5
|
|
|
6
6
|
module Anyway # :nodoc:
|
|
7
|
-
using RubyNext
|
|
8
7
|
using Anyway::Ext::DeepDup
|
|
9
8
|
using Anyway::Ext::DeepFreeze
|
|
10
9
|
using Anyway::Ext::Hash
|
|
@@ -93,7 +92,7 @@ module Anyway # :nodoc:
|
|
|
93
92
|
|
|
94
93
|
unless (reserved_names = (new_keys & RESERVED_NAMES)).empty?
|
|
95
94
|
raise ArgumentError, "Can not use the following reserved names as config attrubutes: " \
|
|
96
|
-
"#{reserved_names.sort.
|
|
95
|
+
"#{reserved_names.sort.join(", ")}"
|
|
97
96
|
end
|
|
98
97
|
|
|
99
98
|
config_attributes.push(*new_keys)
|
|
@@ -154,7 +153,7 @@ module Anyway # :nodoc:
|
|
|
154
153
|
if block
|
|
155
154
|
load_callbacks << BlockCallback.new(block)
|
|
156
155
|
else
|
|
157
|
-
load_callbacks.push(*names.map { it
|
|
156
|
+
load_callbacks.push(*names.map { |it| NamedCallback.new(it) })
|
|
158
157
|
end
|
|
159
158
|
end
|
|
160
159
|
|
|
@@ -261,6 +260,15 @@ module Anyway # :nodoc:
|
|
|
261
260
|
@fallback_type_caster = ::Anyway::NoCast
|
|
262
261
|
end
|
|
263
262
|
|
|
263
|
+
def configuration_sources
|
|
264
|
+
return @configuration_sources if instance_variable_defined?(:@configuration_sources)
|
|
265
|
+
return @configuration_sources = superclass.configuration_sources.dup if superclass.respond_to?(:configuration_sources)
|
|
266
|
+
|
|
267
|
+
@configuration_sources = nil
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
attr_writer :configuration_sources
|
|
271
|
+
|
|
264
272
|
private
|
|
265
273
|
|
|
266
274
|
def define_config_accessor(*names)
|
|
@@ -380,7 +388,7 @@ module Anyway # :nodoc:
|
|
|
380
388
|
trace&.keep_if { |key| self.class.config_attributes.include?(key.to_sym) }
|
|
381
389
|
|
|
382
390
|
# Run on_load callbacks
|
|
383
|
-
self.class.load_callbacks.each { it
|
|
391
|
+
self.class.load_callbacks.each { |it| it.apply_to(self) }
|
|
384
392
|
|
|
385
393
|
# Set trace after we write all the values to
|
|
386
394
|
# avoid changing the source to accessor
|
|
@@ -390,7 +398,10 @@ module Anyway # :nodoc:
|
|
|
390
398
|
end
|
|
391
399
|
|
|
392
400
|
def load_from_sources(base_config, **opts)
|
|
393
|
-
|
|
401
|
+
source_filter = self.class.configuration_sources
|
|
402
|
+
|
|
403
|
+
Anyway.loaders.each do |(id, loader)|
|
|
404
|
+
next if source_filter && !source_filter.include?(id)
|
|
394
405
|
Utils.deep_merge!(base_config, loader.call(**opts))
|
|
395
406
|
end
|
|
396
407
|
base_config
|
|
@@ -29,7 +29,7 @@ module Anyway
|
|
|
29
29
|
def record_value(val, *path, **opts)
|
|
30
30
|
key = path.pop
|
|
31
31
|
trace = if val.is_a?(Hash)
|
|
32
|
-
Trace.new.tap { it
|
|
32
|
+
Trace.new.tap { |it| it.merge_values(val, **opts) }
|
|
33
33
|
else
|
|
34
34
|
Trace.new(:value, val, **opts)
|
|
35
35
|
end
|
|
@@ -84,7 +84,7 @@ module Anyway
|
|
|
84
84
|
|
|
85
85
|
def to_h
|
|
86
86
|
if trace?
|
|
87
|
-
value.transform_values(&:to_h).tap { it
|
|
87
|
+
value.transform_values(&:to_h).tap { |it| it.default_proc = nil }
|
|
88
88
|
else
|
|
89
89
|
{value:, source:}
|
|
90
90
|
end
|
|
@@ -13,9 +13,9 @@ module Anyway
|
|
|
13
13
|
|
|
14
14
|
case val
|
|
15
15
|
when Hash
|
|
16
|
-
val.transform_values { it
|
|
16
|
+
val.transform_values { |it| call(it) }
|
|
17
17
|
when ARRAY_RXP
|
|
18
|
-
val.split(/\s*,\s*/).map { it
|
|
18
|
+
val.split(/\s*,\s*/).map { |it| call(it) }
|
|
19
19
|
when /\A(true|t|yes|y)\z/i
|
|
20
20
|
true
|
|
21
21
|
when /\A(false|f|no|n)\z/i
|
|
@@ -4,7 +4,6 @@ require "anyway/optparse_config"
|
|
|
4
4
|
require "anyway/dynamic_config"
|
|
5
5
|
|
|
6
6
|
module Anyway # :nodoc:
|
|
7
|
-
using RubyNext
|
|
8
7
|
using Anyway::Ext::DeepDup
|
|
9
8
|
using Anyway::Ext::DeepFreeze
|
|
10
9
|
using Anyway::Ext::Hash
|
|
@@ -93,7 +92,7 @@ module Anyway # :nodoc:
|
|
|
93
92
|
|
|
94
93
|
unless (reserved_names = (new_keys & RESERVED_NAMES)).empty?
|
|
95
94
|
raise ArgumentError, "Can not use the following reserved names as config attrubutes: " \
|
|
96
|
-
"#{reserved_names.sort.
|
|
95
|
+
"#{reserved_names.sort.join(", ")}"
|
|
97
96
|
end
|
|
98
97
|
|
|
99
98
|
config_attributes.push(*new_keys)
|
|
@@ -154,7 +153,7 @@ module Anyway # :nodoc:
|
|
|
154
153
|
if block
|
|
155
154
|
load_callbacks << BlockCallback.new(block)
|
|
156
155
|
else
|
|
157
|
-
load_callbacks.push(*names.map { it
|
|
156
|
+
load_callbacks.push(*names.map { |it| NamedCallback.new(it) })
|
|
158
157
|
end
|
|
159
158
|
end
|
|
160
159
|
|
|
@@ -261,6 +260,15 @@ module Anyway # :nodoc:
|
|
|
261
260
|
@fallback_type_caster = ::Anyway::NoCast
|
|
262
261
|
end
|
|
263
262
|
|
|
263
|
+
def configuration_sources
|
|
264
|
+
return @configuration_sources if instance_variable_defined?(:@configuration_sources)
|
|
265
|
+
return @configuration_sources = superclass.configuration_sources.dup if superclass.respond_to?(:configuration_sources)
|
|
266
|
+
|
|
267
|
+
@configuration_sources = nil
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
attr_writer :configuration_sources
|
|
271
|
+
|
|
264
272
|
private
|
|
265
273
|
|
|
266
274
|
def define_config_accessor(*names)
|
|
@@ -380,7 +388,7 @@ module Anyway # :nodoc:
|
|
|
380
388
|
trace&.keep_if { |key| self.class.config_attributes.include?(key.to_sym) }
|
|
381
389
|
|
|
382
390
|
# Run on_load callbacks
|
|
383
|
-
self.class.load_callbacks.each { it
|
|
391
|
+
self.class.load_callbacks.each { |it| it.apply_to(self) }
|
|
384
392
|
|
|
385
393
|
# Set trace after we write all the values to
|
|
386
394
|
# avoid changing the source to accessor
|
|
@@ -390,7 +398,10 @@ module Anyway # :nodoc:
|
|
|
390
398
|
end
|
|
391
399
|
|
|
392
400
|
def load_from_sources(base_config, **opts)
|
|
393
|
-
|
|
401
|
+
source_filter = self.class.configuration_sources
|
|
402
|
+
|
|
403
|
+
Anyway.loaders.each do |(id, loader)|
|
|
404
|
+
next if source_filter && !source_filter.include?(id)
|
|
394
405
|
Utils.deep_merge!(base_config, loader.call(**opts))
|
|
395
406
|
end
|
|
396
407
|
base_config
|
|
@@ -29,7 +29,7 @@ module Anyway
|
|
|
29
29
|
def record_value(val, *path, **opts)
|
|
30
30
|
key = path.pop
|
|
31
31
|
trace = if val.is_a?(Hash)
|
|
32
|
-
Trace.new.tap { it
|
|
32
|
+
Trace.new.tap { |it| it.merge_values(val, **opts) }
|
|
33
33
|
else
|
|
34
34
|
Trace.new(:value, val, **opts)
|
|
35
35
|
end
|
|
@@ -84,7 +84,7 @@ module Anyway
|
|
|
84
84
|
|
|
85
85
|
def to_h
|
|
86
86
|
if trace?
|
|
87
|
-
value.transform_values(&:to_h).tap { it
|
|
87
|
+
value.transform_values(&:to_h).tap { |it| it.default_proc = nil }
|
|
88
88
|
else
|
|
89
89
|
{value:, source:}
|
|
90
90
|
end
|
data/lib/anyway/config.rb
CHANGED
|
@@ -4,7 +4,6 @@ require "anyway/optparse_config"
|
|
|
4
4
|
require "anyway/dynamic_config"
|
|
5
5
|
|
|
6
6
|
module Anyway # :nodoc:
|
|
7
|
-
using RubyNext
|
|
8
7
|
using Anyway::Ext::DeepDup
|
|
9
8
|
using Anyway::Ext::DeepFreeze
|
|
10
9
|
using Anyway::Ext::Hash
|
|
@@ -93,7 +92,7 @@ module Anyway # :nodoc:
|
|
|
93
92
|
|
|
94
93
|
unless (reserved_names = (new_keys & RESERVED_NAMES)).empty?
|
|
95
94
|
raise ArgumentError, "Can not use the following reserved names as config attrubutes: " \
|
|
96
|
-
"#{reserved_names.sort.
|
|
95
|
+
"#{reserved_names.sort.join(", ")}"
|
|
97
96
|
end
|
|
98
97
|
|
|
99
98
|
config_attributes.push(*new_keys)
|
|
@@ -261,6 +260,15 @@ module Anyway # :nodoc:
|
|
|
261
260
|
@fallback_type_caster = ::Anyway::NoCast
|
|
262
261
|
end
|
|
263
262
|
|
|
263
|
+
def configuration_sources
|
|
264
|
+
return @configuration_sources if instance_variable_defined?(:@configuration_sources)
|
|
265
|
+
return @configuration_sources = superclass.configuration_sources.dup if superclass.respond_to?(:configuration_sources)
|
|
266
|
+
|
|
267
|
+
@configuration_sources = nil
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
attr_writer :configuration_sources
|
|
271
|
+
|
|
264
272
|
private
|
|
265
273
|
|
|
266
274
|
def define_config_accessor(*names)
|
|
@@ -390,7 +398,10 @@ module Anyway # :nodoc:
|
|
|
390
398
|
end
|
|
391
399
|
|
|
392
400
|
def load_from_sources(base_config, **opts)
|
|
393
|
-
|
|
401
|
+
source_filter = self.class.configuration_sources
|
|
402
|
+
|
|
403
|
+
Anyway.loaders.each do |(id, loader)|
|
|
404
|
+
next if source_filter && !source_filter.include?(id)
|
|
394
405
|
Utils.deep_merge!(base_config, loader.call(**opts))
|
|
395
406
|
end
|
|
396
407
|
base_config
|
data/lib/anyway/env.rb
CHANGED
data/lib/anyway/loaders/env.rb
CHANGED
data/lib/anyway/loaders/yaml.rb
CHANGED
data/lib/anyway/loaders.rb
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
using RubyNext
|
|
3
|
+
require "anyway/loaders/base"
|
|
5
4
|
|
|
5
|
+
module Anyway
|
|
6
6
|
module Loaders
|
|
7
|
+
autoload :YAML, "anyway/loaders/yaml"
|
|
8
|
+
autoload :Env, "anyway/loaders/env"
|
|
9
|
+
autoload :EJSON, "anyway/loaders/ejson"
|
|
10
|
+
autoload :Doppler, "anyway/loaders/doppler"
|
|
11
|
+
|
|
7
12
|
class Registry
|
|
8
13
|
attr_reader :registry
|
|
9
14
|
|
|
@@ -55,6 +60,8 @@ module Anyway
|
|
|
55
60
|
registry.each(&block)
|
|
56
61
|
end
|
|
57
62
|
|
|
63
|
+
def keys() = registry.map(&:first)
|
|
64
|
+
|
|
58
65
|
def freeze() = registry.freeze
|
|
59
66
|
|
|
60
67
|
private
|
|
@@ -71,9 +78,3 @@ module Anyway
|
|
|
71
78
|
end
|
|
72
79
|
end
|
|
73
80
|
end
|
|
74
|
-
|
|
75
|
-
require "anyway/loaders/base"
|
|
76
|
-
require "anyway/loaders/yaml"
|
|
77
|
-
require "anyway/loaders/env"
|
|
78
|
-
require "anyway/loaders/doppler"
|
|
79
|
-
require "anyway/loaders/ejson"
|