config 5.4.0 → 5.5.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: 9695bee8465b0c65165242a23d7df19a04047c78d131587f87b5c0e356930a6c
4
- data.tar.gz: 13b9ee27af8ad78c2450111854c1f8498b1019d0cd8c358eaa986bd0d01b8541
3
+ metadata.gz: c8c55570ed35c36e29bb0e7fd02b4aa449fb1edf17b5c43739526d33c68bc67b
4
+ data.tar.gz: 0cdf118110c9761a24944e2cb810123ec26242efc820e8b47545ff2cc6219f86
5
5
  SHA512:
6
- metadata.gz: a15b3c5112f4f776f2df92d28fa4ac8d6d0dc92eeb294b863b0be055696d8a3cc7de4abbd44aab28cd31c9e2d716e8debbcae84a439758bd1ac9d5c4415da264
7
- data.tar.gz: 65b04c96cf9e826fccceeff15a5897c19e2a617ab131922c1ab395dfe4aad8fe6320c5c5916b07f80c75c98369460cd9a252201d684da667a37a543edea4651e
6
+ metadata.gz: f698950933d9c7830b10d6849c8b249df8ea63ef2b8ddc6111c5dfc5f47f7173ef3049744cbbf30c95660b5b3caa98ababd61f269f1bc74be7227a15be244797
7
+ data.tar.gz: 6078e1863615b7115af836136dc3759cc62815a85ea23a3a8f9a9ff671f2246b5059bcec0549ed61398c863ea834d861741890c55fac5e31f091d3c3ab438af5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.5.0
4
+
5
+ ### New features
6
+
7
+ * Allow arrays to be passed through env variables ([#354](https://github.com/rubyconfig/config/pull/354))
8
+
9
+ ### Documentation
10
+
11
+ * Use funding_url rather than post_install_message ([#360](https://github.com/rubyconfig/config/pull/360))
12
+ * Fix typos in the tests and documentation ([#359](https://github.com/rubyconfig/config/pull/359))
13
+
3
14
  ## 5.4.0
4
15
 
5
16
  ### New features
@@ -56,7 +67,7 @@
56
67
  * Rails versions `< 5.2` are no longer supported ([#316](https://github.com/rubyconfig/config/pull/316))
57
68
  * Ruby versions `< 2.6` are no longer supported ([#316](https://github.com/rubyconfig/config/pull/316))
58
69
  * Support `HashSource` and `EnvSource` instances in `Config.load_files` and `Config.load_and_set_settings`. ([#315](https://github.com/rubyconfig/config/pull/315)). There are a few subtle breaking changes:
59
- * Previously, `Config.load_files` (called from `Config.load_and_set_settings`) would call `.to_s` on each of its arguments. Now, this responsibility is defered to YAMLSource. In effect, if your application passes String or Pathname objects to `Config.load_files`, no changes are necessary, but if you were somehow relying on the `.to_s` call for some other type of object, you'll now need to call `.to_s` on that object before passing it to `Config`.
70
+ * Previously, `Config.load_files` (called from `Config.load_and_set_settings`) would call `.to_s` on each of its arguments. Now, this responsibility is deferred to YAMLSource. In effect, if your application passes String or Pathname objects to `Config.load_files`, no changes are necessary, but if you were somehow relying on the `.to_s` call for some other type of object, you'll now need to call `.to_s` on that object before passing it to `Config`.
60
71
  * Before this change, `Config.load_files` would call `uniq` on its argument array. This call has been removed, so duplicate file paths are not removed before further processing. In some cases, this can cause differences in behavior since later config files override the values in earlier ones. In most cases, it's best to ensure that duplicate paths are not passed to `Config.load_files`.
61
72
 
62
73
  ## 3.1.1
data/README.md CHANGED
@@ -428,7 +428,7 @@ ENV['Settings.section.server'] = 'google.com'
428
428
 
429
429
  It won't work with arrays, though.
430
430
 
431
- It is considered an error to use environment variables to simutaneously assign a "flat" value and a multi-level value to a key.
431
+ It is considered an error to use environment variables to simultaneously assign a "flat" value and a multi-level value to a key.
432
432
 
433
433
  ```ruby
434
434
  # Raises an error when settings are loaded
data/config.gemspec CHANGED
@@ -14,13 +14,10 @@ Gem::Specification.new do |s|
14
14
  s.license = 'MIT'
15
15
  s.extra_rdoc_files = %w[README.md CHANGELOG.md CONTRIBUTING.md LICENSE.md]
16
16
  s.rdoc_options = ['--charset=UTF-8']
17
- s.post_install_message = "\n\e[33mThanks for installing Config\e[0m
18
- Please consider donating to our open collective to help us maintain this project.
19
- \n
20
- Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n"
21
17
 
22
18
  s.metadata = {
23
19
  'changelog_uri' => "https://github.com/rubyconfig/config/blob/master/CHANGELOG.md",
20
+ 'funding_url' => 'https://opencollective.com/rubyconfig/donate',
24
21
  'source_code_uri' => 'https://github.com/rubyconfig/config',
25
22
  'bug_tracker_uri' => 'https://github.com/rubyconfig/config/issues'
26
23
  }
@@ -6,17 +6,20 @@ module Config
6
6
  attr_reader :separator
7
7
  attr_reader :converter
8
8
  attr_reader :parse_values
9
+ attr_reader :parse_arrays
9
10
 
10
11
  def initialize(env,
11
12
  prefix: Config.env_prefix || Config.const_name,
12
13
  separator: Config.env_separator,
13
14
  converter: Config.env_converter,
14
- parse_values: Config.env_parse_values)
15
+ parse_values: Config.env_parse_values,
16
+ parse_arrays: Config.env_parse_arrays)
15
17
  @env = env
16
18
  @prefix = prefix.to_s.split(separator)
17
19
  @separator = separator
18
20
  @converter = converter
19
21
  @parse_values = parse_values
22
+ @parse_arrays = parse_arrays
20
23
  end
21
24
 
22
25
  def load
@@ -52,10 +55,28 @@ module Config
52
55
  leaf[keys.last] = parse_values ? __value(value) : value
53
56
  end
54
57
 
55
- hash
58
+ parse_arrays ? convert_hashes_to_arrays(hash) : hash
56
59
  end
57
60
 
58
61
  private
62
+ def convert_hashes_to_arrays(hash)
63
+ hash.each_with_object({}) do |(key, value), new_hash|
64
+ if value.is_a?(Hash)
65
+ value = convert_hashes_to_arrays(value)
66
+ if consecutive_numeric_keys?(value.keys)
67
+ new_hash[key] = value.keys.sort_by(&:to_i).map { |k| value[k] }
68
+ else
69
+ new_hash[key] = value
70
+ end
71
+ else
72
+ new_hash[key] = value
73
+ end
74
+ end
75
+ end
76
+
77
+ def consecutive_numeric_keys?(keys)
78
+ keys.map(&:to_i).sort == (0...keys.size).to_a && keys.all? { |k| k == k.to_i.to_s }
79
+ end
59
80
 
60
81
  # Try to convert string to a correct type
61
82
  def __value(v)
@@ -1,3 +1,3 @@
1
1
  module Config
2
- VERSION = '5.4.0'.freeze
2
+ VERSION = '5.5.0'.freeze
3
3
  end
data/lib/config.rb CHANGED
@@ -18,6 +18,7 @@ module Config
18
18
  env_separator: '.',
19
19
  env_converter: :downcase,
20
20
  env_parse_values: true,
21
+ env_parse_arrays: false,
21
22
  fail_on_missing: false,
22
23
  file_name: 'settings',
23
24
  dir_name: 'settings',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.0
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Kuczynski
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-03-16 00:00:00.000000000 Z
13
+ date: 2024-05-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: deep_merge
@@ -264,10 +264,10 @@ licenses:
264
264
  - MIT
265
265
  metadata:
266
266
  changelog_uri: https://github.com/rubyconfig/config/blob/master/CHANGELOG.md
267
+ funding_url: https://opencollective.com/rubyconfig/donate
267
268
  source_code_uri: https://github.com/rubyconfig/config
268
269
  bug_tracker_uri: https://github.com/rubyconfig/config/issues
269
- post_install_message: "\n\e[33mThanks for installing Config\e[0m\nPlease consider
270
- donating to our open collective to help us maintain this project.\n\n\nDonate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n"
270
+ post_install_message:
271
271
  rdoc_options:
272
272
  - "--charset=UTF-8"
273
273
  require_paths:
@@ -283,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
283
  - !ruby/object:Gem::Version
284
284
  version: '0'
285
285
  requirements: []
286
- rubygems_version: 3.4.22
286
+ rubygems_version: 3.5.4
287
287
  signing_key:
288
288
  specification_version: 4
289
289
  summary: Effortless multi-environment settings in Rails, Sinatra, Padrino and others