anyway_config 2.2.2 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +20 -0
- data/lib/.rbnext/2.7/anyway/auto_cast.rb +2 -2
- data/lib/.rbnext/2.7/anyway/rails/loaders/yaml.rb +8 -2
- data/lib/.rbnext/3.0/anyway/auto_cast.rb +2 -2
- data/lib/.rbnext/{1995.next → 3.1}/anyway/config.rb +0 -0
- data/lib/.rbnext/{1995.next → 3.1}/anyway/dynamic_config.rb +0 -0
- data/lib/.rbnext/{1995.next → 3.1}/anyway/env.rb +0 -0
- data/lib/.rbnext/{1995.next → 3.1}/anyway/loaders/base.rb +0 -0
- data/lib/.rbnext/{1995.next → 3.1}/anyway/tracing.rb +0 -0
- data/lib/anyway/auto_cast.rb +2 -2
- data/lib/anyway/loaders/yaml.rb +12 -4
- data/lib/anyway/rails/loaders/yaml.rb +8 -2
- data/lib/anyway/rails/settings.rb +5 -0
- data/lib/anyway/tracing.rb +1 -1
- data/lib/anyway/version.rb +1 -1
- data/lib/generators/anyway/install/templates/application_config.rb.tt +1 -1
- metadata +11 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e4b1e98155e34f0220746d9230e433072143638e838f8975023c79cf75a9fe1
|
4
|
+
data.tar.gz: e5d8b4f78fe7f32fc2dd3068f90897a28f57a292596346f5bb368a36094cea36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 849c9c7fb4bc1101444dfec952a84ac3b1f605f3415d65d31ea727f176d9281cddc90e8b56ff73a3b25431126d61640931cfbc2621dc607493014e9a97d4ee3a
|
7
|
+
data.tar.gz: 840073b4420e4c1a792db2571b29eb7605cbc7066833bc4afe91defd94ba08153a4f32036a6cd09c6cf8f1da718f7f11d41bb46c8b9ea1ab0a0bfd2a81ab0a20
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 2.2.3 (2022-01-21)
|
6
|
+
|
7
|
+
- Fix Ruby 3.1 compatibility. ([@palkan][])
|
8
|
+
|
9
|
+
- Add ability to set default key for environmental YAML files. ([@skryukov])
|
10
|
+
|
11
|
+
Define a key for environmental yaml files to read default values from with `config.anyway_config.default_environmental_key = "default"`.
|
12
|
+
This way Anyway Config will try to read settings under the `"default"` key and then merge environmental settings into them.
|
13
|
+
|
5
14
|
## 2.2.2 (2020-10-26)
|
6
15
|
|
7
16
|
- Fixed regression introduced by the `#deep_merge!` refinement.
|
@@ -439,3 +448,4 @@ No we're dependency-free!
|
|
439
448
|
[@jastkand]: https://github.com/jastkand
|
440
449
|
[@envek]: https://github.com/Envek
|
441
450
|
[@progapandist]: https://github.com/progapandist
|
451
|
+
[@skryukov]: https://github.com/skryukov
|
data/README.md
CHANGED
@@ -373,6 +373,26 @@ staging:
|
|
373
373
|
port: 3002 # This value will not be loaded at all
|
374
374
|
```
|
375
375
|
|
376
|
+
To provide default values you can use YAML anchors, but they do not deep-merge settings, so Anyway Config provides a way to define a special top-level key for default values like this:
|
377
|
+
|
378
|
+
```ruby
|
379
|
+
config.anyway_config.default_environmental_key = "default"
|
380
|
+
```
|
381
|
+
|
382
|
+
After that, Anyway Config will start reading settings under the `"default"` key and then merge environmental settings into them.
|
383
|
+
|
384
|
+
```yml
|
385
|
+
default:
|
386
|
+
server: # This values will be loaded in all environments by default
|
387
|
+
host: localhost
|
388
|
+
port: 3002
|
389
|
+
|
390
|
+
staging:
|
391
|
+
server:
|
392
|
+
host: staging.example.com # This value will override the defaults when Rails.env.staging? is true
|
393
|
+
# port will be set to the value from the defaults — 3002
|
394
|
+
```
|
395
|
+
|
376
396
|
You can specify the lookup path for YAML files in one of the following ways:
|
377
397
|
|
378
398
|
- By setting `config.anyway_config.default_config_path` to a target directory path:
|
@@ -4,8 +4,8 @@ module Anyway
|
|
4
4
|
module AutoCast
|
5
5
|
# Regexp to detect array values
|
6
6
|
# Array value is a values that contains at least one comma
|
7
|
-
# and doesn't start/end with quote
|
8
|
-
ARRAY_RXP = /\A[^'"].*\s*,\s*.*[^'"]\z/
|
7
|
+
# and doesn't start/end with quote or curly braces
|
8
|
+
ARRAY_RXP = /\A[^'"{].*\s*,\s*.*[^'"}]\z/
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def call(val)
|
@@ -8,7 +8,11 @@ module Anyway
|
|
8
8
|
parsed_yml = super
|
9
9
|
return parsed_yml unless environmental?(parsed_yml)
|
10
10
|
|
11
|
-
|
11
|
+
env_config = parsed_yml[::Rails.env] || {}
|
12
|
+
return env_config if Anyway::Settings.default_environmental_key.blank?
|
13
|
+
|
14
|
+
default_config = parsed_yml[Anyway::Settings.default_environmental_key] || {}
|
15
|
+
Utils.deep_merge!(default_config, env_config)
|
12
16
|
end
|
13
17
|
|
14
18
|
private
|
@@ -18,7 +22,9 @@ module Anyway
|
|
18
22
|
# likely
|
19
23
|
return true if parsed_yml.key?(::Rails.env)
|
20
24
|
# less likely
|
21
|
-
::Rails.application.config.anyway_config.known_environments.any? { |_1| parsed_yml.key?(_1) }
|
25
|
+
return true if ::Rails.application.config.anyway_config.known_environments.any? { |_1| parsed_yml.key?(_1) }
|
26
|
+
# strange, but still possible
|
27
|
+
Anyway::Settings.default_environmental_key.present? && parsed_yml.key?(Anyway::Settings.default_environmental_key)
|
22
28
|
end
|
23
29
|
|
24
30
|
def relative_config_path(path)
|
@@ -4,8 +4,8 @@ module Anyway
|
|
4
4
|
module AutoCast
|
5
5
|
# Regexp to detect array values
|
6
6
|
# Array value is a values that contains at least one comma
|
7
|
-
# and doesn't start/end with quote
|
8
|
-
ARRAY_RXP = /\A[^'"].*\s*,\s*.*[^'"]\z/
|
7
|
+
# and doesn't start/end with quote or curly braces
|
8
|
+
ARRAY_RXP = /\A[^'"{].*\s*,\s*.*[^'"}]\z/
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def call(val)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/anyway/auto_cast.rb
CHANGED
@@ -4,8 +4,8 @@ module Anyway
|
|
4
4
|
module AutoCast
|
5
5
|
# Regexp to detect array values
|
6
6
|
# Array value is a values that contains at least one comma
|
7
|
-
# and doesn't start/end with quote
|
8
|
-
ARRAY_RXP = /\A[^'"].*\s*,\s*.*[^'"]\z/
|
7
|
+
# and doesn't start/end with quote or curly braces
|
8
|
+
ARRAY_RXP = /\A[^'"{].*\s*,\s*.*[^'"}]\z/
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def call(val)
|
data/lib/anyway/loaders/yaml.rb
CHANGED
@@ -29,10 +29,18 @@ module Anyway
|
|
29
29
|
# By default, YAML load will return `false` when the yaml document is
|
30
30
|
# empty. When this occurs, we return an empty hash instead, to match
|
31
31
|
# the interface when no config file is present.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
begin
|
33
|
+
if defined?(ERB)
|
34
|
+
::YAML.load(ERB.new(File.read(path)).result, aliases: true) || {} # rubocop:disable Security/YAMLLoad
|
35
|
+
else
|
36
|
+
::YAML.load_file(path, aliases: true) || {}
|
37
|
+
end
|
38
|
+
rescue ArgumentError
|
39
|
+
if defined?(ERB)
|
40
|
+
::YAML.load(ERB.new(File.read(path)).result) || {} # rubocop:disable Security/YAMLLoad
|
41
|
+
else
|
42
|
+
::YAML.load_file(path) || {}
|
43
|
+
end
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
@@ -8,7 +8,11 @@ module Anyway
|
|
8
8
|
parsed_yml = super
|
9
9
|
return parsed_yml unless environmental?(parsed_yml)
|
10
10
|
|
11
|
-
|
11
|
+
env_config = parsed_yml[::Rails.env] || {}
|
12
|
+
return env_config if Anyway::Settings.default_environmental_key.blank?
|
13
|
+
|
14
|
+
default_config = parsed_yml[Anyway::Settings.default_environmental_key] || {}
|
15
|
+
Utils.deep_merge!(default_config, env_config)
|
12
16
|
end
|
13
17
|
|
14
18
|
private
|
@@ -18,7 +22,9 @@ module Anyway
|
|
18
22
|
# likely
|
19
23
|
return true if parsed_yml.key?(::Rails.env)
|
20
24
|
# less likely
|
21
|
-
::Rails.application.config.anyway_config.known_environments.any? { parsed_yml.key?(_1) }
|
25
|
+
return true if ::Rails.application.config.anyway_config.known_environments.any? { parsed_yml.key?(_1) }
|
26
|
+
# strange, but still possible
|
27
|
+
Anyway::Settings.default_environmental_key.present? && parsed_yml.key?(Anyway::Settings.default_environmental_key)
|
22
28
|
end
|
23
29
|
|
24
30
|
def relative_config_path(path)
|
@@ -17,6 +17,9 @@ module Anyway
|
|
17
17
|
attr_reader :autoload_static_config_path, :autoloader
|
18
18
|
attr_accessor :known_environments
|
19
19
|
|
20
|
+
# Define a key for environmental yaml files to read default values from
|
21
|
+
attr_accessor :default_environmental_key
|
22
|
+
|
20
23
|
if defined?(::Zeitwerk)
|
21
24
|
def autoload_static_config_path=(val)
|
22
25
|
raise "Cannot setup autoloader after application has been initialized" if ::Rails.application.initialized?
|
@@ -63,5 +66,7 @@ module Anyway
|
|
63
66
|
|
64
67
|
self.default_config_path = ->(name) { ::Rails.root.join("config", "#{name}.yml") }
|
65
68
|
self.known_environments = %w[test development production]
|
69
|
+
# Don't try read defaults when no key defined
|
70
|
+
self.default_environmental_key = nil
|
66
71
|
end
|
67
72
|
end
|
data/lib/anyway/tracing.rb
CHANGED
data/lib/anyway/version.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
class ApplicationConfig < Anyway::Config
|
5
5
|
class << self
|
6
6
|
# Make it possible to access a singleton config instance
|
7
|
-
# via class methods (i.e., without
|
7
|
+
# via class methods (i.e., without explicitly calling `instance`)
|
8
8
|
delegate_missing_to :instance
|
9
9
|
|
10
10
|
private
|
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.2.
|
4
|
+
version: 2.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-next-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.14.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.14.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: ammeter
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.14.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: steep
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
96
|
+
version: 0.14.0
|
111
97
|
description: "\n Configuration DSL for Ruby libraries and applications.\n Allows
|
112
98
|
you to easily follow the twelve-factor application principles (https://12factor.net/config).\n
|
113
99
|
\ "
|
@@ -120,11 +106,6 @@ files:
|
|
120
106
|
- CHANGELOG.md
|
121
107
|
- LICENSE.txt
|
122
108
|
- README.md
|
123
|
-
- lib/.rbnext/1995.next/anyway/config.rb
|
124
|
-
- lib/.rbnext/1995.next/anyway/dynamic_config.rb
|
125
|
-
- lib/.rbnext/1995.next/anyway/env.rb
|
126
|
-
- lib/.rbnext/1995.next/anyway/loaders/base.rb
|
127
|
-
- lib/.rbnext/1995.next/anyway/tracing.rb
|
128
109
|
- lib/.rbnext/2.7/anyway/auto_cast.rb
|
129
110
|
- lib/.rbnext/2.7/anyway/config.rb
|
130
111
|
- lib/.rbnext/2.7/anyway/rails/loaders/yaml.rb
|
@@ -137,6 +118,11 @@ files:
|
|
137
118
|
- lib/.rbnext/3.0/anyway/loaders.rb
|
138
119
|
- lib/.rbnext/3.0/anyway/loaders/base.rb
|
139
120
|
- lib/.rbnext/3.0/anyway/tracing.rb
|
121
|
+
- lib/.rbnext/3.1/anyway/config.rb
|
122
|
+
- lib/.rbnext/3.1/anyway/dynamic_config.rb
|
123
|
+
- lib/.rbnext/3.1/anyway/env.rb
|
124
|
+
- lib/.rbnext/3.1/anyway/loaders/base.rb
|
125
|
+
- lib/.rbnext/3.1/anyway/tracing.rb
|
140
126
|
- lib/anyway.rb
|
141
127
|
- lib/anyway/auto_cast.rb
|
142
128
|
- lib/anyway/config.rb
|