gonfic 0.3.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 +7 -0
- data/.rubocop.yml +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +16 -0
- data/gonfic.gemspec +36 -0
- data/lib/gonfic/config.rb +11 -0
- data/lib/gonfic/version.rb +5 -0
- data/lib/gonfic.rb +17 -0
- metadata +71 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e2fad61828080ba4b9eb70df2a48a73c96f36c57838ba1995352729798418aba
|
|
4
|
+
data.tar.gz: b8aefe5e2a0382397db5b29051d16206fd881bd80417330a4b7f158d7f1ed237
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f87f1745b1a4de1fca0b71304a48d3edbd3ef28420ca1de05aed0e782c583c7c2be58fdba43416d05a15284af799c623233fcdc2b5e55a8ad595134ffedf7202
|
|
7
|
+
data.tar.gz: f2a204863ba25f38dfe81a05820b3ef5a2dc21e203c4f6dacb6516833b05741f429b19905d713813eedd23bfdeb66fd2074007e01d6e20f056ca0b9e9fe6341a
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
AllCops:
|
|
3
|
+
TargetRubyVersion: 2.6
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
NewCops: enable
|
|
6
|
+
|
|
7
|
+
Style/FrozenStringLiteralComment:
|
|
8
|
+
Enabled: false
|
|
9
|
+
|
|
10
|
+
Layout/EndOfLine:
|
|
11
|
+
Enabled: true
|
|
12
|
+
EnforcedStyle: lf
|
|
13
|
+
|
|
14
|
+
# tab country begins
|
|
15
|
+
Layout/IndentationStyle:
|
|
16
|
+
Enabled: true
|
|
17
|
+
EnforcedStyle: tabs
|
|
18
|
+
|
|
19
|
+
Layout/IndentationWidth: # weird setting to enable other Layout cops to work with tabs
|
|
20
|
+
Enabled: true
|
|
21
|
+
Width: 1
|
|
22
|
+
# tab country ends
|
|
23
|
+
|
|
24
|
+
Layout/SpaceBeforeBlockBraces:
|
|
25
|
+
Enabled: true
|
|
26
|
+
EnforcedStyle: no_space
|
|
27
|
+
|
|
28
|
+
Layout/LineLength:
|
|
29
|
+
Max: 120
|
|
30
|
+
|
|
31
|
+
Style/StringLiterals:
|
|
32
|
+
Enabled: true
|
|
33
|
+
EnforcedStyle: single_quotes
|
|
34
|
+
|
|
35
|
+
Style/StringLiteralsInInterpolation:
|
|
36
|
+
Enabled: true
|
|
37
|
+
EnforcedStyle: single_quotes
|
|
38
|
+
|
|
39
|
+
Style/TrailingCommaInArrayLiteral:
|
|
40
|
+
Enabled: true
|
|
41
|
+
EnforcedStyleForMultiline: comma
|
|
42
|
+
|
|
43
|
+
Style/TrailingCommaInHashLiteral:
|
|
44
|
+
Enabled: true
|
|
45
|
+
EnforcedStyleForMultiline: comma
|
|
46
|
+
|
|
47
|
+
Layout/SpaceInsideHashLiteralBraces:
|
|
48
|
+
Enabled: true
|
|
49
|
+
EnforcedStyle: no_space
|
|
50
|
+
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Emil Chludziński
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Gonfic
|
|
2
|
+
|
|
3
|
+
Tool-oriented configuration: merge config from ~/, ./, ENV, and OptionParser, access as Hashie::Mash
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add `gem 'gonfic'` to your application's `Gemfile`, then run `bundle install`.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
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
|
|
15
|
+
|
|
16
|
+
## Design
|
|
17
|
+
|
|
18
|
+
`Gonfic` is intended to be used with tools - small, often commandline programs.
|
|
19
|
+
It will merge configuration from multiple sources, in increasing order of specificity.
|
|
20
|
+
You can also think about these sources in terms of how long-lived they are:
|
|
21
|
+
|
|
22
|
+
* `config_defaults:`: this is what you determine when writing the tool - lasts as long as this particular tool,
|
|
23
|
+
* `~/$CONFIGURATION_FILENAME`: this will be applied every time a particular user uses your tool,
|
|
24
|
+
* `./$CONFIGURATION_FILENAME`: every time that user uses your tool, in a particular directory (e.g. source code checkout),
|
|
25
|
+
* `ENV` variables: every time your tool is used during a particular session (so it can override directory settings, but persists over multiple runs),
|
|
26
|
+
* `OptionParser`'d settings: during a single, particular run.
|
|
27
|
+
|
|
28
|
+
In the intended scenario (where you allow the config to be slightly flexible) you will barely need to configure your tool's config, aside from providing `config_defaults:` once. No listing of allowed setting readers, no spelling out options and types, no mapping to formats - `Gonfic` takes care of all that's needed.
|
|
29
|
+
|
|
30
|
+
## Why not...?
|
|
31
|
+
|
|
32
|
+
### https://github.com/bkeepers/dotenv or https://github.com/rubyconfig/config
|
|
33
|
+
|
|
34
|
+
These are application-oriented: they have robust support for multiple environments and integration with frameworks.
|
|
35
|
+
|
|
36
|
+
### https://dry-rb.org/gems/dry-configurable/main/
|
|
37
|
+
|
|
38
|
+
This is more for library developers: allows you to add configurable settings to an object, which other code will later use.
|
|
39
|
+
|
|
40
|
+
### https://github.com/cjbottaro/config_spartan
|
|
41
|
+
|
|
42
|
+
This one is actually kind of cool, in its minimalism - and intended for similar usage scenarios. But it doesn't seem to be actively developed nowadays, and I wanted a few more features, mostly around some opinionated/automagical defaults.
|
|
43
|
+
|
|
44
|
+
## Advanced scenarios
|
|
45
|
+
|
|
46
|
+
### Deferring dangerous operations
|
|
47
|
+
|
|
48
|
+
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:
|
|
49
|
+
|
|
50
|
+
module MyTool
|
|
51
|
+
def self.config
|
|
52
|
+
@config ||= Gonfic.new(...)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
In this way you are lazily deferring the "dangerous" operations until first usage, then memoizing.
|
|
57
|
+
Additionally, with access to your config via a method that's easy to stub, your test suite will be happy :)
|
|
58
|
+
|
|
59
|
+
## Source code
|
|
60
|
+
|
|
61
|
+
https://gitlab.com/tanstaafl/gonfic
|
|
62
|
+
|
|
63
|
+
## Development
|
|
64
|
+
|
|
65
|
+
Your first steps should be:
|
|
66
|
+
|
|
67
|
+
git clone git@gitlab.com:tanstaafl/gonfic.git
|
|
68
|
+
cd gonfic
|
|
69
|
+
bundle install
|
|
70
|
+
bundle exec rake
|
|
71
|
+
|
|
72
|
+
This will run tests (Minitest) and linter (Rubocop, custom config, see `.rubocop.yml`).
|
|
73
|
+
|
|
74
|
+
Note: the repo does not force the bundle to be vendorized,
|
|
75
|
+
but should work fine if you set `BUNDLE_PATH: "vendor"` in your `~/.bundle/config`.
|
|
76
|
+
|
|
77
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
78
|
+
|
|
79
|
+
To install this gem onto your local machine from sources, run `bundle exec rake install`.
|
|
80
|
+
|
|
81
|
+
## Contributing
|
|
82
|
+
|
|
83
|
+
Bug reports and merge requests are welcome on GitLab at https://gitlab.com/tanstaafl/gonfic.
|
|
84
|
+
|
|
85
|
+
## Name
|
|
86
|
+
|
|
87
|
+
Yeah, it's not great. As in: not obvious.
|
|
88
|
+
If you would prefer it to be better:
|
|
89
|
+
|
|
90
|
+
1. Go to https://rubygems.org/gems?letter=C
|
|
91
|
+
2. Binary-search to `conf*` (at this stage you might begin to appreciate how hard naming is in this particular case, I hope).
|
|
92
|
+
3. Send me an issue (or a merge request, or something) with a better name that's available on RubyGems! :D
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << 'test'
|
|
8
|
+
t.libs << 'lib'
|
|
9
|
+
t.test_files = FileList['test/**/test_*.rb']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require 'rubocop/rake_task'
|
|
13
|
+
|
|
14
|
+
RuboCop::RakeTask.new
|
|
15
|
+
|
|
16
|
+
task default: %i[rubocop test]
|
data/gonfic.gemspec
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/gonfic/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'gonfic'
|
|
7
|
+
spec.version = Gonfic::VERSION
|
|
8
|
+
spec.authors = ['Emil Chludziński']
|
|
9
|
+
spec.email = ['tanstaafl@tlen.pl']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Gonfic - merge config from ~/, ./, ENV, and OptionParser - access as Hashie::Mash.'
|
|
12
|
+
spec.description = <<~DESCRIPTION
|
|
13
|
+
Gonfic
|
|
14
|
+
Configuration gem for commandline tools.
|
|
15
|
+
Provides easy access to config, merged from multiple sources in order of specificity.
|
|
16
|
+
DESCRIPTION
|
|
17
|
+
spec.homepage = 'https://gitlab.com/tanstaafl/gonfic'
|
|
18
|
+
spec.license = 'MIT'
|
|
19
|
+
spec.required_ruby_version = '>= 2.6.0'
|
|
20
|
+
|
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
22
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
|
23
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
24
|
+
|
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
File.expand_path(f) == __FILE__ ||
|
|
28
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
spec.bindir = 'exe'
|
|
32
|
+
spec.executables = spec.files.grep(%r{\Aexe/}){ |f| File.basename(f) }
|
|
33
|
+
spec.require_paths = ['lib']
|
|
34
|
+
|
|
35
|
+
spec.add_dependency 'hashie'
|
|
36
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'hashie/mash'
|
|
2
|
+
require 'hashie/extensions/mash/safe_assignment'
|
|
3
|
+
require 'hashie/extensions/mash/symbolize_keys'
|
|
4
|
+
|
|
5
|
+
module Gonfic
|
|
6
|
+
# loads, stores, and allows access to configuration
|
|
7
|
+
class Config < Hashie::Mash
|
|
8
|
+
include Hashie::Extensions::Mash::SafeAssignment
|
|
9
|
+
include Hashie::Extensions::Mash::SymbolizeKeys
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/gonfic.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'gonfic/version'
|
|
4
|
+
require_relative 'gonfic/config'
|
|
5
|
+
|
|
6
|
+
# external interface to creating a Config with data loaded from files
|
|
7
|
+
module Gonfic
|
|
8
|
+
def self.new(defaults: {}, filename: nil)
|
|
9
|
+
config = Config.new(defaults)
|
|
10
|
+
config.merge!(load_configuration_file("~/#{filename}"))
|
|
11
|
+
config.merge!(load_configuration_file("./#{filename}"))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.load_configuration_file(filename)
|
|
15
|
+
YAML.safe_load(File.read(filename))
|
|
16
|
+
end
|
|
17
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gonfic
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Emil Chludziński
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-07-12 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: hashie
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: |
|
|
28
|
+
Gonfic
|
|
29
|
+
Configuration gem for commandline tools.
|
|
30
|
+
Provides easy access to config, merged from multiple sources in order of specificity.
|
|
31
|
+
email:
|
|
32
|
+
- tanstaafl@tlen.pl
|
|
33
|
+
executables: []
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- ".rubocop.yml"
|
|
38
|
+
- LICENSE.txt
|
|
39
|
+
- README.md
|
|
40
|
+
- Rakefile
|
|
41
|
+
- gonfic.gemspec
|
|
42
|
+
- lib/gonfic.rb
|
|
43
|
+
- lib/gonfic/config.rb
|
|
44
|
+
- lib/gonfic/version.rb
|
|
45
|
+
homepage: https://gitlab.com/tanstaafl/gonfic
|
|
46
|
+
licenses:
|
|
47
|
+
- MIT
|
|
48
|
+
metadata:
|
|
49
|
+
homepage_uri: https://gitlab.com/tanstaafl/gonfic
|
|
50
|
+
source_code_uri: https://gitlab.com/tanstaafl/gonfic
|
|
51
|
+
rubygems_mfa_required: 'true'
|
|
52
|
+
post_install_message:
|
|
53
|
+
rdoc_options: []
|
|
54
|
+
require_paths:
|
|
55
|
+
- lib
|
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 2.6.0
|
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
|
+
requirements:
|
|
63
|
+
- - ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '0'
|
|
66
|
+
requirements: []
|
|
67
|
+
rubygems_version: 3.4.15
|
|
68
|
+
signing_key:
|
|
69
|
+
specification_version: 4
|
|
70
|
+
summary: Gonfic - merge config from ~/, ./, ENV, and OptionParser - access as Hashie::Mash.
|
|
71
|
+
test_files: []
|