anyway_config 2.2.2 → 2.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc95d6a5792ef79aaa6abc3156e11fb9cfe45c48637f6763d16ec5b4645667fb
4
- data.tar.gz: 13c6d72ce0d659945e08f2e6e457f745876338d4fdc74a94a5cd049e201b5904
3
+ metadata.gz: 0e4b1e98155e34f0220746d9230e433072143638e838f8975023c79cf75a9fe1
4
+ data.tar.gz: e5d8b4f78fe7f32fc2dd3068f90897a28f57a292596346f5bb368a36094cea36
5
5
  SHA512:
6
- metadata.gz: a4bdc75c88708b8da49ced8b757e897b0bb6a8f21787ebaee65c5b154518fd343203b583542078058159c53bed0ba5700ed01f66387901a75e440e072cd3cbad
7
- data.tar.gz: f6410c3f38b6d877b4ae9ba6adde192957fed52bba5943242c80420d742a266c0739c45a9105054dc04da921219a179e30ca8811b065b2dfbd70d3523d4b6f2c
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
- super[::Rails.env] || {}
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
@@ -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)
@@ -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
- if defined?(ERB)
33
- ::YAML.load(ERB.new(File.read(path)).result) || {} # rubocop:disable Security/YAMLLoad
34
- else
35
- ::YAML.load_file(path) || {}
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
- super[::Rails.env] || {}
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
@@ -86,7 +86,7 @@ module Anyway
86
86
  if trace?
87
87
  value.transform_values(&:to_h).tap { _1.default_proc = nil }
88
88
  else
89
- {value, source}
89
+ {value:, source:}
90
90
  end
91
91
  end
92
92
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyway # :nodoc:
4
- VERSION = "2.2.2"
4
+ VERSION = "2.2.3"
5
5
  end
@@ -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 explictly calling `instance`)
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.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: 2021-10-26 00:00:00.000000000 Z
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.11.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.11.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: '0.8'
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: '0.8'
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