konfigyu 0.1.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/.circleci/config.yml +30 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +108 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/konfigyu.gemspec +38 -0
- data/lib/konfigyu.rb +14 -0
- data/lib/konfigyu/config.rb +102 -0
- data/lib/konfigyu/exceptions.rb +7 -0
- data/lib/konfigyu/version.rb +6 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f4325b1cc0a2ef8ef7bb54e8275616ab4f54d859d4ec93e8c9432a5aa7016f3f
|
4
|
+
data.tar.gz: f91b299f09c3145f457cd70002e5219bb573cab51fb48da25f24ea2ac4172c1d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 427f916d357a4189dee69e45745bdd94590c62072da88a3d68df0a605927032b498eb5d298e263b0e29bc33f1195c71e70a430f7943e3859c6aa330a169e15b7
|
7
|
+
data.tar.gz: a581cdd82b0a0d984d4b3c6f969593ecb5bc99ddb190f41eaf92239b3cf72775c10e3f0ec34ae09eb76e81058764329dd0467db554c9698b18166126a7cd1663
|
@@ -0,0 +1,30 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
working_directory: ~/konfigyu
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.5.1-node-browsers
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
|
10
|
+
- type: cache-restore
|
11
|
+
name: Restore bundle cache
|
12
|
+
key: initrax-bundle-{{ checksum "Gemfile.lock" }}
|
13
|
+
|
14
|
+
- run:
|
15
|
+
name: Bundle Install
|
16
|
+
command: bundle install --path vendor/bundle
|
17
|
+
|
18
|
+
- type: cache-save
|
19
|
+
name: Store bundle cache
|
20
|
+
key: initrax-bundle-{{ checksum "Gemfile.lock" }}
|
21
|
+
paths:
|
22
|
+
- vendor/bundle
|
23
|
+
|
24
|
+
- run:
|
25
|
+
name: Rubocop
|
26
|
+
command: bundle exec rubocop
|
27
|
+
|
28
|
+
- run:
|
29
|
+
name: Run Rspec specs
|
30
|
+
command: bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# This is the configuration used to check the rubocop source code.
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop/cop/internal_affairs
|
5
|
+
- rubocop-rspec
|
6
|
+
|
7
|
+
AllCops:
|
8
|
+
Exclude:
|
9
|
+
- 'vendor/**/*'
|
10
|
+
- 'spec/fixtures/**/*'
|
11
|
+
- 'tmp/**/*'
|
12
|
+
TargetRubyVersion: 2.2
|
13
|
+
|
14
|
+
Naming/PredicateName:
|
15
|
+
# Method define macros for dynamically generated method.
|
16
|
+
MethodDefinitionMacros:
|
17
|
+
- define_method
|
18
|
+
- define_singleton_method
|
19
|
+
- def_node_matcher
|
20
|
+
- def_node_search
|
21
|
+
|
22
|
+
Style/FrozenStringLiteralComment:
|
23
|
+
EnforcedStyle: always
|
24
|
+
|
25
|
+
Style/FormatStringToken:
|
26
|
+
# Because we parse a lot of source codes from strings. Percent arrays
|
27
|
+
# look like unannotated format string tokens to this cop.
|
28
|
+
Exclude:
|
29
|
+
- spec/**/*
|
30
|
+
|
31
|
+
Style/IpAddresses:
|
32
|
+
# The test for this cop includes strings that would cause offenses
|
33
|
+
Exclude:
|
34
|
+
- spec/rubocop/cop/style/ip_addresses_spec.rb
|
35
|
+
|
36
|
+
Layout/EndOfLine:
|
37
|
+
EnforcedStyle: lf
|
38
|
+
|
39
|
+
Layout/ClassStructure:
|
40
|
+
Enabled: true
|
41
|
+
Categories:
|
42
|
+
module_inclusion:
|
43
|
+
- include
|
44
|
+
- prepend
|
45
|
+
- extend
|
46
|
+
ExpectedOrder:
|
47
|
+
- module_inclusion
|
48
|
+
- constants
|
49
|
+
- public_class_methods
|
50
|
+
- initializer
|
51
|
+
- instance_methods
|
52
|
+
- protected_methods
|
53
|
+
- private_methods
|
54
|
+
|
55
|
+
Layout/IndentHeredoc:
|
56
|
+
EnforcedStyle: powerpack
|
57
|
+
|
58
|
+
# Trailing white space is meaningful in code examples
|
59
|
+
Layout/TrailingWhitespace:
|
60
|
+
AllowInHeredoc: true
|
61
|
+
|
62
|
+
Lint/AmbiguousBlockAssociation:
|
63
|
+
Exclude:
|
64
|
+
- 'spec/**/*.rb'
|
65
|
+
|
66
|
+
Lint/InterpolationCheck:
|
67
|
+
Exclude:
|
68
|
+
- 'spec/**/*.rb'
|
69
|
+
|
70
|
+
Lint/UselessAccessModifier:
|
71
|
+
MethodCreatingMethods:
|
72
|
+
- 'def_matcher'
|
73
|
+
- 'def_node_matcher'
|
74
|
+
|
75
|
+
Lint/BooleanSymbol:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Metrics/AbcSize:
|
79
|
+
Max: 20
|
80
|
+
|
81
|
+
Metrics/CyclomaticComplexity:
|
82
|
+
Max: 10
|
83
|
+
|
84
|
+
Metrics/LineLength:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
Metrics/BlockLength:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
Metrics/ModuleLength:
|
91
|
+
Exclude:
|
92
|
+
- 'spec/**/*.rb'
|
93
|
+
|
94
|
+
Performance/Caller:
|
95
|
+
Exclude:
|
96
|
+
- spec/rubocop/cop/performance/caller_spec.rb
|
97
|
+
|
98
|
+
RSpec/PredicateMatcher:
|
99
|
+
EnforcedStyle: inflected
|
100
|
+
|
101
|
+
RSpec/NestedGroups:
|
102
|
+
Max: 7
|
103
|
+
|
104
|
+
RSpec/MultipleExpectations:
|
105
|
+
Max: 2
|
106
|
+
|
107
|
+
RSpec/ExampleLength:
|
108
|
+
Enabled: false
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
konfigyu
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tgourley@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
konfigyu (0.1.0)
|
5
|
+
syck (~> 1.3.0)
|
6
|
+
sycl (~> 1.6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.0)
|
12
|
+
byebug (10.0.2)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
jaro_winkler (1.5.1)
|
15
|
+
parallel (1.12.1)
|
16
|
+
parser (2.5.1.2)
|
17
|
+
ast (~> 2.4.0)
|
18
|
+
powerpack (0.1.2)
|
19
|
+
rainbow (3.0.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.8.0)
|
22
|
+
rspec-core (~> 3.8.0)
|
23
|
+
rspec-expectations (~> 3.8.0)
|
24
|
+
rspec-mocks (~> 3.8.0)
|
25
|
+
rspec-core (3.8.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-expectations (3.8.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.8.0)
|
30
|
+
rspec-mocks (3.8.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.8.0)
|
33
|
+
rspec-support (3.8.0)
|
34
|
+
rubocop (0.59.2)
|
35
|
+
jaro_winkler (~> 1.5.1)
|
36
|
+
parallel (~> 1.10)
|
37
|
+
parser (>= 2.5, != 2.5.1.1)
|
38
|
+
powerpack (~> 0.1)
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
42
|
+
rubocop-rspec (1.29.1)
|
43
|
+
rubocop (>= 0.58.0)
|
44
|
+
ruby-progressbar (1.10.0)
|
45
|
+
syck (1.3.0)
|
46
|
+
sycl (1.6)
|
47
|
+
unicode-display_width (1.4.0)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
bundler (~> 1.16)
|
54
|
+
byebug (~> 10.0.2)
|
55
|
+
konfigyu!
|
56
|
+
rake (~> 10.0)
|
57
|
+
rspec (~> 3.8.0)
|
58
|
+
rubocop (~> 0.59.2)
|
59
|
+
rubocop-rspec (~> 1.29.1)
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.16.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Tim Gourley
|
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
|
+
# Konfigyu
|
2
|
+
|
3
|
+
## コンフィギュ
|
4
|
+
|
5
|
+

|
6
|
+

|
7
|
+

|
8
|
+

|
9
|
+
|
10
|
+
When adding an application-specific YAML config file to your project, often you end up writing a bunch
|
11
|
+
of boilerplate code to manage the file's location, reading in the contents, and managing required values.
|
12
|
+
|
13
|
+
This gem strives to make this an easier process to manage so you can start writing your application quicker.
|
14
|
+
It relies on the sycl and syck gems for loading the yaml.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'konfigyu'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install konfigyu
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### Basic Usage
|
35
|
+
|
36
|
+
Create a YAML config file. For example, `~/konfigyu.yml`
|
37
|
+
|
38
|
+
```yaml
|
39
|
+
foo:
|
40
|
+
bar: value
|
41
|
+
baz: something-else
|
42
|
+
log:
|
43
|
+
level: info
|
44
|
+
```
|
45
|
+
|
46
|
+
Then, in your code, you can instantiate a new `Konfigyu::Config` object pointing to that file:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'konfigyu'
|
50
|
+
|
51
|
+
config = Konfigyu::Config.new('~/konfigyu.yml')
|
52
|
+
```
|
53
|
+
|
54
|
+
You can access the config values through `data` or through array `[]` notation:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
puts config.data.foo.baz # Outputs "something-else"
|
58
|
+
puts config['data.foo.baz'] # Also outputs "something-else"
|
59
|
+
```
|
60
|
+
|
61
|
+
### Required values
|
62
|
+
|
63
|
+
You can ensure that certain values are required, and optionally that they contain specific values
|
64
|
+
by passing in a hash of options to Konfigyu:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
require 'konfigyu'
|
68
|
+
|
69
|
+
config = Konfigyu::Config.new('~/konfigyu.yml' {
|
70
|
+
required_fields: ['foo', 'foo.bar', 'log', 'log.level'],
|
71
|
+
required_values: { 'log.level': %w[none fatal error warn info debug] }
|
72
|
+
})
|
73
|
+
```
|
74
|
+
|
75
|
+
Note that if you do not list a field in `required_fields` but include it in `required_values`, it
|
76
|
+
will stil validate the contents of the field, but only if the field is non-empty.
|
77
|
+
|
78
|
+
If validation fails, a `Konfigui::InvalidConfigException` will be raised.
|
79
|
+
|
80
|
+
## Development
|
81
|
+
|
82
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
83
|
+
|
84
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bratta/konfigyu. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
93
|
+
|
94
|
+
## Code of Conduct
|
95
|
+
|
96
|
+
Everyone interacting in the Konfigyu project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bratta/konfigyu/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: false
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'konfigyu'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require 'pry'
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/konfigyu.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'konfigyu/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'konfigyu'
|
9
|
+
spec.version = Konfigyu::VERSION
|
10
|
+
spec.authors = ['Tim Gourley']
|
11
|
+
spec.email = ['tgourley@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Easily manage YAML config files for your application.'
|
14
|
+
spec.description = 'Allows for customization of your YAML config file with basic requirements.'
|
15
|
+
spec.homepage = 'https://github.com/bratta/konfigyu'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
# Required dependencies
|
28
|
+
spec.add_dependency 'syck', '~> 1.3.0'
|
29
|
+
spec.add_dependency 'sycl', '~> 1.6'
|
30
|
+
|
31
|
+
# Development Dependencies
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
33
|
+
spec.add_development_dependency 'byebug', '~> 10.0.2'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.8.0'
|
36
|
+
spec.add_development_dependency 'rubocop', '~> 0.59.2'
|
37
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.29.1'
|
38
|
+
end
|
data/lib/konfigyu.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'syck'
|
6
|
+
require 'sycl'
|
7
|
+
|
8
|
+
require 'konfigyu/version'
|
9
|
+
require 'konfigyu/exceptions'
|
10
|
+
require 'konfigyu/config'
|
11
|
+
|
12
|
+
# Define the module namespace for this gem
|
13
|
+
module Konfigyu
|
14
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This is the main module code for the gem
|
4
|
+
module Konfigyu
|
5
|
+
# Does the meat of the work
|
6
|
+
class Config
|
7
|
+
attr_accessor :config_file, :data, :options
|
8
|
+
|
9
|
+
DEFAULT_FILENAME = 'konfigyu.yml'.freeze
|
10
|
+
DEFAULT_EXAMPLE_FILENAME = 'konfigyu.yml.example'.freeze
|
11
|
+
|
12
|
+
# Options Example:
|
13
|
+
#
|
14
|
+
# options = {
|
15
|
+
# required_fields: [
|
16
|
+
# 'top_level', 'top_level.second_level_field',
|
17
|
+
# 'log', 'log.level',
|
18
|
+
# ],
|
19
|
+
# required_values: {
|
20
|
+
# 'log.level': %w{none fatal error warn info debug},
|
21
|
+
# }
|
22
|
+
# }
|
23
|
+
|
24
|
+
def initialize(config_file = nil, options = {})
|
25
|
+
self.config_file = config_file.nil? ? File.expand_path("~/#{DEFAULT_FILENAME}") : File.expand_path(config_file)
|
26
|
+
if !self.config_file || !File.exist?(self.config_file)
|
27
|
+
raise Konfigyu::FileNotFoundException, "Missing configuration file: #{self.config_file}"
|
28
|
+
end
|
29
|
+
|
30
|
+
self.data = Sycl.load_file(self.config_file)
|
31
|
+
@options = initialize_options(options)
|
32
|
+
validate
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate
|
36
|
+
validate_usage
|
37
|
+
validate_required_fields
|
38
|
+
validate_required_values
|
39
|
+
end
|
40
|
+
|
41
|
+
def [](key)
|
42
|
+
data.get(key)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def validate_usage
|
48
|
+
config_usage = "See #{DEFAULT_EXAMPLE_FILENAME} for more information on configuration."
|
49
|
+
msg = "Missing configuration data for #{config_file}."
|
50
|
+
msg += "\n#{config_usage}" if File.exist?(DEFAULT_EXAMPLE_FILENAME)
|
51
|
+
raise Konfigyu::InvalidConfigException, msg unless data
|
52
|
+
end
|
53
|
+
|
54
|
+
def validate_required_fields
|
55
|
+
errors = []
|
56
|
+
(@options[:required_fields] || []).each do |required_field|
|
57
|
+
errors.push(required_field) unless deep_key_exists?(required_field)
|
58
|
+
end
|
59
|
+
|
60
|
+
msg = "Missing required configuration elements: #{errors.join(', ')}"
|
61
|
+
raise Konfigyu::InvalidConfigException, msg if errors.count > 0
|
62
|
+
end
|
63
|
+
|
64
|
+
def validate_required_values
|
65
|
+
errors = []
|
66
|
+
(@options[:required_values] || {}).each_pair do |key, required_value|
|
67
|
+
value = data.get(key.to_s)
|
68
|
+
next if !options[:required_fields].include?(key) && (value.nil? || value.empty?)
|
69
|
+
|
70
|
+
errors.push(key) unless required_value.include?(value)
|
71
|
+
end
|
72
|
+
|
73
|
+
msg = "One or more keys missing required value: #{errors.join(', ')}"
|
74
|
+
raise Konfigyu::InvalidConfigException, msg if errors.count > 0
|
75
|
+
end
|
76
|
+
|
77
|
+
def default_options
|
78
|
+
{
|
79
|
+
required_fields: [],
|
80
|
+
required_values: {}
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def initialize_options(options = {})
|
85
|
+
valid_keys = default_options.keys
|
86
|
+
{}.merge(default_options).tap do |sanitized_option|
|
87
|
+
unless options.keys.empty?
|
88
|
+
options.keys.each do |key|
|
89
|
+
sanitized_key = key.downcase.to_sym
|
90
|
+
sanitized_option[sanitized_key] = options[key] if valid_keys.include?(sanitized_key)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def deep_key_exists?(config_key)
|
97
|
+
data.get(config_key)
|
98
|
+
rescue NoMethodError
|
99
|
+
false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: konfigyu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Gourley
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: syck
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sycl
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.0.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 10.0.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.8.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.8.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.59.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.59.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.29.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.29.1
|
125
|
+
description: Allows for customization of your YAML config file with basic requirements.
|
126
|
+
email:
|
127
|
+
- tgourley@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".circleci/config.yml"
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".rubocop.yml"
|
136
|
+
- ".ruby-gemset"
|
137
|
+
- ".ruby-version"
|
138
|
+
- CODE_OF_CONDUCT.md
|
139
|
+
- Gemfile
|
140
|
+
- Gemfile.lock
|
141
|
+
- LICENSE.txt
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- bin/console
|
145
|
+
- bin/setup
|
146
|
+
- konfigyu.gemspec
|
147
|
+
- lib/konfigyu.rb
|
148
|
+
- lib/konfigyu/config.rb
|
149
|
+
- lib/konfigyu/exceptions.rb
|
150
|
+
- lib/konfigyu/version.rb
|
151
|
+
homepage: https://github.com/bratta/konfigyu
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.7.6
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Easily manage YAML config files for your application.
|
175
|
+
test_files: []
|