gonfic 0.6.2 → 0.7.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: 7b8810655c20a36c4ae9220d82652bd740f7a9b108f62fa6c34400c39d8af4d0
4
- data.tar.gz: 4202e4993d903c3fe560730ff88e798728617f2db71d92bc9f5de1127ca30888
3
+ metadata.gz: 5540b5acbed6a77e6822f0aea120d20cac396ec86c7011edf7b665fe82e2f96b
4
+ data.tar.gz: e27a4fa9e41ae1696a14192835c5e31290a146dd3719708cf1bee481747c5c26
5
5
  SHA512:
6
- metadata.gz: 4dd9ed806e8982e2be4103930ab51291b3c93c4163f044b5ebbdd63edc72b6bf369d4b2be8c597c5da66a8d83bce4e116171f1021c4238284e54cc6a3f36092b
7
- data.tar.gz: 6828d7979ccc5589531c81d2f4f063fcf5d8511749f97445d58c6a8aff6ce2befa75a808d67f6f1e8db89d843a837cee237a5feb40a981146e9567b9a1473432
6
+ metadata.gz: f5310196e4f2681a3f1b931101f7349782700b8b57666b517fc21625808f00272a41bf42a03f84692a4ca5caf0a1b05a58da249362bab242b14dad2565141b6e
7
+ data.tar.gz: 70f3c1f5fe26fd365657b9480265cf8efbe5f9ff7f4a6eb9959cab6d95355d1312bd7dd88a5ede693f0539ff1b0a7b35be59bbfb1532fe0c49f1c09369819dc0
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2023 Emil Chludziński
3
+ Copyright (c) 2023-2025 Emil Chludziński
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -8,10 +8,12 @@ Add `gem 'gonfic'` to your application's `Gemfile`, then run `bundle install`.
8
8
 
9
9
  ## Usage
10
10
 
11
- CONFIGURATION_FILENAME = '.my_tool' # YAML config file format, by default
12
- CONFIGURATION_DEFAULTS = {a: 1, b: {c: 2}} # will deep_merge! using Hashie magic
13
- CONFIG = Gonfic.new(filename: CONFIGURATION_FILENAME, defaults: CONFIGURATION_DEFAULTS)
14
- puts CONFIG.b.c
11
+ ```ruby
12
+ CONFIGURATION_FILENAME = '.my_tool' # YAML config file format, by default
13
+ CONFIGURATION_DEFAULTS = {a: 1, b: {c: 2}} # will deep_merge! using Hashie magic
14
+ CONFIG = Gonfic.new(filename: CONFIGURATION_FILENAME, defaults: CONFIGURATION_DEFAULTS)
15
+ puts CONFIG.b.c
16
+ ```
15
17
 
16
18
  ## Design
17
19
 
@@ -49,11 +51,13 @@ As 90+% of the functionality is configured by different ways of calling `Gonfic.
49
51
 
50
52
  The `Gonfic.new` call will peform file I/O and other operations, which can potentially fail and raise errors. Doing things like that is generally frowned upon in initializers and immediately when files are `require`d - so `CONFIG = Gonfic.new` might not be the best practice ever, succinct as it is. A more prudent approach would be:
51
53
 
52
- module MyTool
53
- def self.config
54
- @config ||= Gonfic.new(...)
55
- end
54
+ ```ruby
55
+ module MyTool
56
+ def self.config
57
+ @config ||= Gonfic.new(...)
56
58
  end
59
+ end
60
+ ```
57
61
 
58
62
  In this way you are lazily deferring the "dangerous" operations until first usage, then memoizing.
59
63
  Additionally, with access to your config via a method that's easy to stub, your test suite will be happy :)
@@ -63,6 +67,32 @@ Additionally, with access to your config via a method that's easy to stub, your
63
67
  By default, `Gonfic.new` will look for `filename:` in `~/` and `./` (merging them, if both are present).
64
68
  If you want to load from other directories, just set the `directories:` parameter to your list.
65
69
 
70
+ ### Providing list of full paths (when filenames differ)
71
+
72
+ Alternatively, you don't have to use the same `.my_tool` configuration filename, but instead support e.g. all of these:
73
+
74
+ ```
75
+ ~
76
+ ├── .my_tool.yml
77
+ └── .config
78
+ ├── my_tool.yml
79
+ └── my_tool
80
+ ├── aliases.yml
81
+ └── secrets.yml
82
+ ```
83
+
84
+ If you want these files to be merged, set the `file_paths:` parameter to a list of full paths including filenames:
85
+
86
+ ```ruby
87
+ CONFIG = Gonfic.new(
88
+ file_paths: %w[~/.my_tool.yml ~/.config/my_tool.yml ~/.config/my_tool/aliases.yml ~/.config/my_tool/secrets.yml],
89
+ defaults: CONFIGURATION_DEFAULTS,
90
+ )
91
+ ```
92
+
93
+ All the paths passed to `Gonfic.new`, either in `directories:` + `filename:`, or in `file_paths:` mode, are
94
+ passed through `File.expand_path` - so you can use `~/` and `./` as parts of the path parameters.
95
+
66
96
  ### Loading configuration from ENV
67
97
 
68
98
  If you provide `filename:`, `Gonfic.new` will also check `ENV` for variables it considers relevant.
@@ -71,7 +101,7 @@ The pattern, in general, is that `.tool-name` becomes `TOOL_NAME_*` - and any va
71
101
 
72
102
  To disable this behavior, set `env_variable_prefix:` to falsey (`nil` will do).
73
103
 
74
- You can also override the prefix. Underscore at the end is optional.
104
+ You can also override the prefix - set it independently from `filename:`. Underscore at the end is optional.
75
105
 
76
106
  ## Source code
77
107
 
@@ -1,3 +1,3 @@
1
1
  module Gonfic
2
- VERSION = '0.6.2'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
data/lib/gonfic.rb CHANGED
@@ -9,14 +9,14 @@ require_relative 'gonfic/directories'
9
9
  module Gonfic
10
10
  YAML_FILE_LOADER = ->(filename){ YAML.safe_load(File.read(filename)) }
11
11
 
12
- def self.new(
13
- defaults: {},
14
- filename: nil, file_loader: YAML_FILE_LOADER, directories: Directories.home_then_here,
12
+ def self.new( # rubocop:disable Metrics/ParameterLists
13
+ defaults: {}, file_loader: YAML_FILE_LOADER,
14
+ filename: nil, directories: Directories.home_then_here, file_paths: join_into_paths(directories, filename),
15
15
  env_variable_prefix: EnvExtractor.env_prefix_from_filename(filename)
16
16
  )
17
17
  configs =
18
18
  configs_from_defaults(defaults: defaults) +
19
- configs_from_files(filename: filename, file_loader: file_loader, directories: directories) +
19
+ configs_from_files(file_loader: file_loader, file_paths: file_paths) +
20
20
  configs_from_env(env_variable_prefix: env_variable_prefix, defaults: defaults)
21
21
 
22
22
  configs.reduce(:merge!)
@@ -26,11 +26,16 @@ module Gonfic
26
26
  [Config.new(defaults)]
27
27
  end
28
28
 
29
- def self.configs_from_files(filename:, file_loader:, directories:)
30
- return [] unless filename
29
+ def self.join_into_paths(directories, filename)
30
+ return [] unless directories && filename
31
31
 
32
- directories.map do |directory|
33
- filepath = File.expand_path(File.join(directory, filename))
32
+ directories.map{ |directory| File.expand_path(File.join(directory, filename)) }
33
+ end
34
+
35
+ def self.configs_from_files(file_loader:, file_paths:)
36
+ return [] unless file_paths
37
+
38
+ file_paths.map do |filepath|
34
39
  load_configuration_file(filepath, file_loader)
35
40
  end
36
41
  end
@@ -39,8 +44,8 @@ module Gonfic
39
44
  return {} unless File.exist?(filename)
40
45
 
41
46
  file_loader.call(filename)
42
- rescue StandardError => e
43
- Hashie.logger.error(e)
47
+ rescue StandardError => exc
48
+ Hashie.logger.error(exc)
44
49
  {}
45
50
  end
46
51
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gonfic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Chludziński
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-08-19 00:00:00.000000000 Z
10
+ date: 2025-04-07 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: hashie
@@ -36,7 +35,6 @@ extra_rdoc_files: []
36
35
  files:
37
36
  - LICENSE.txt
38
37
  - README.md
39
- - gonfic.gemspec
40
38
  - lib/gonfic.rb
41
39
  - lib/gonfic/config.rb
42
40
  - lib/gonfic/directories.rb
@@ -49,7 +47,6 @@ metadata:
49
47
  homepage_uri: https://gitlab.com/tanstaafl/gonfic
50
48
  source_code_uri: https://gitlab.com/tanstaafl/gonfic
51
49
  rubygems_mfa_required: 'true'
52
- post_install_message:
53
50
  rdoc_options: []
54
51
  require_paths:
55
52
  - lib
@@ -57,15 +54,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
54
  requirements:
58
55
  - - ">="
59
56
  - !ruby/object:Gem::Version
60
- version: 2.6.0
57
+ version: 2.7.0
61
58
  required_rubygems_version: !ruby/object:Gem::Requirement
62
59
  requirements:
63
60
  - - ">="
64
61
  - !ruby/object:Gem::Version
65
62
  version: '0'
66
63
  requirements: []
67
- rubygems_version: 3.4.15
68
- signing_key:
64
+ rubygems_version: 3.6.2
69
65
  specification_version: 4
70
66
  summary: Gonfic - merge config from ~/, ./, ENV, and OptionParser - access as Hashie::Mash.
71
67
  test_files: []
data/gonfic.gemspec DELETED
@@ -1,34 +0,0 @@
1
- require_relative 'lib/gonfic/version'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'gonfic'
5
- spec.version = Gonfic::VERSION
6
- spec.authors = ['Emil Chludziński']
7
- spec.email = ['tanstaafl@tlen.pl']
8
-
9
- spec.summary = 'Gonfic - merge config from ~/, ./, ENV, and OptionParser - access as Hashie::Mash.'
10
- spec.description = <<~DESCRIPTION
11
- Gonfic:
12
- Configuration gem for commandline tools.
13
- Provides easy access to config, merged from multiple sources in order of specificity.
14
- DESCRIPTION
15
- spec.homepage = 'https://gitlab.com/tanstaafl/gonfic'
16
- spec.license = 'MIT'
17
- spec.required_ruby_version = '>= 2.6.0'
18
-
19
- spec.metadata['homepage_uri'] = spec.homepage
20
- spec.metadata['source_code_uri'] = spec.homepage
21
- spec.metadata['rubygems_mfa_required'] = 'true'
22
-
23
- spec.files = Dir.chdir(__dir__) do
24
- `git ls-files -z`.split("\x0").reject do |f|
25
- File.expand_path(f) == __FILE__ ||
26
- f.start_with?(*%w[bin/ test/ .git .rubocop.yml Gemfile Rakefile])
27
- end
28
- end
29
- spec.bindir = 'exe'
30
- spec.executables = spec.files.grep(%r{\Aexe/}){ |f| File.basename(f) }
31
- spec.require_paths = ['lib']
32
-
33
- spec.add_dependency 'hashie'
34
- end