gonfic 0.7.1 → 0.8.0

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: 6ecd1286abfa268a78ffb750a5f47fe2be0eb90249c566bea5a9362c3b4d54ad
4
- data.tar.gz: 5854cc9db210db4c3a45885ceecf6b43db5c486c96819fd4d30445bb0d23ccf9
3
+ metadata.gz: 9625ccea4705117429f2e8dcd26dfff874b7bbd4d4048066f11c211a5cb3ceda
4
+ data.tar.gz: 9fa059cdc03712e05aabe4640800aca11779f79d31b8af2ed54ebae5401b7a05
5
5
  SHA512:
6
- metadata.gz: 6ae7706db4df2837309c6b03ce3a14c3b6cf810b916f549fb780a0825e893f037e2c8768df8e3702244b4584c6762ac531ae07c128654ab8ad2461bf14274632
7
- data.tar.gz: 6110157ff9cc6bb5f403b1c89709c36f0e8919cd4c8afbef5fcdc88824c4ff0440761f497b0791fc212ac4e2cb8dde02412ccecc0e4996f39d6984c2e888c4be
6
+ metadata.gz: '086d1c383cec53d12b65e119775d71888ff296e01499132d3fef0037e2a78b5f8c334b67e7be8e7d64bf7d15cc8f578ab11901b4af83de7ca33aad7178335bbd'
7
+ data.tar.gz: 79d172024364ebcba9479e7f468150bfa66dad91d1fe5f7e8798cd0e5fa1521a2dd189a5b235bfaa804ffb54fed22192125e2742db5606719dc493139a1cb7d8
data/README.md CHANGED
@@ -128,7 +128,12 @@ To install this gem onto your local machine from sources, run `bundle exec rake
128
128
 
129
129
  In `fish` syntax, even if you are on Windows:
130
130
  ```sh
131
- gem bump -v patch; dos2unix (fd version.rb); and bundle install; and bundle exec rake; and git commit -a --amend
131
+ gem bump -v patch # or `minor`, or `major`; requires https://github.com/svenfuchs/gem-release
132
+ dos2unix (fd version.rb) # if you are using MinGW on Windows and suffer from CRLF
133
+ bundle install # to bump the version in Gemfile.lock
134
+ git commit -a --amend # add Gemfile.lock to the version bump
135
+ bundle exec rake # last minute sanity check
136
+ bundle exec rake release # push to RubyGems
132
137
  ```
133
138
 
134
139
  ## Contributing
@@ -4,13 +4,27 @@ module Gonfic
4
4
  def self.extract_variables_from_env(prefix:, defaults:)
5
5
  extracted = {}
6
6
 
7
- defaults.each_key do |key_name|
8
- extract_variable(prefix: prefix, key_name: key_name, into: extracted)
7
+ linearize_keys(defaults).each do |key_path|
8
+ extract_variable(prefix: prefix, key_path: key_path, into: extracted)
9
9
  end
10
10
 
11
11
  extracted
12
12
  end
13
13
 
14
+ def self.linearize_keys(hash, parents: [])
15
+ linear = []
16
+
17
+ hash.each do |k, v|
18
+ if v.is_a?(Hash)
19
+ linear += linearize_keys(v, parents: parents + [k])
20
+ else
21
+ linear << (parents + [k])
22
+ end
23
+ end
24
+
25
+ linear
26
+ end
27
+
14
28
  def self.env_prefix_from_filename(filename)
15
29
  return nil unless filename
16
30
 
@@ -19,18 +33,18 @@ module Gonfic
19
33
  "#{converted}_"
20
34
  end
21
35
 
22
- def self.upcase_and_simplify(sym)
23
- sym
24
- .to_s
25
- .gsub(/[^\w]+/, '_')
26
- .delete_prefix('_')
27
- .delete_suffix('_')
28
- .upcase
36
+ def self.upcase_and_simplify(*key_path)
37
+ key_path.map do |key|
38
+ key.to_s.gsub(/[^\w]+/, '_').delete_prefix('_').delete_suffix('_')
39
+ end.join('__').upcase
29
40
  end
30
41
 
31
- def self.extract_variable(prefix:, key_name:, into:)
32
- env_var_name = prefix + upcase_and_simplify(key_name)
33
- into[key_name] = env.fetch(env_var_name) if env.key?(env_var_name)
42
+ def self.extract_variable(prefix:, key_path:, into:)
43
+ env_var_name = prefix + upcase_and_simplify(*key_path)
44
+ return unless env.key?(env_var_name)
45
+
46
+ into = into[key_path.shift] ||= {} while key_path.length > 1
47
+ into[key_path.last] = env.fetch(env_var_name)
34
48
  end
35
49
 
36
50
  def self.env
@@ -1,3 +1,3 @@
1
1
  module Gonfic
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
data/lib/gonfic.rb CHANGED
@@ -7,7 +7,7 @@ require_relative 'gonfic/directories'
7
7
 
8
8
  # external interface to creating a Config with data loaded from files
9
9
  module Gonfic
10
- YAML_FILE_LOADER = ->(filename){ YAML.safe_load(File.read(filename)) }
10
+ YAML_FILE_LOADER = ->(filename){ YAML.safe_load(File.read(filename)) || {} }
11
11
 
12
12
  def self.new( # rubocop:disable Metrics/ParameterLists
13
13
  defaults: {}, file_loader: YAML_FILE_LOADER,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gonfic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Chludziński
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: hashie
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.6.2
64
+ rubygems_version: 3.6.7
65
65
  specification_version: 4
66
66
  summary: Gonfic - merge config from ~/, ./, ENV, and OptionParser - access as Hashie::Mash.
67
67
  test_files: []