yaml_extend 0.2.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +14 -14
- data/.rspec +2 -2
- data/.travis.yml +5 -5
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +4 -4
- data/LICENSE +21 -21
- data/README.md +181 -164
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/custom_errors/invalid_key_type_error.rb +1 -1
- data/lib/yaml_extend.rb +199 -130
- data/lib/yaml_extend/version.rb +3 -3
- data/yaml_extend.gemspec +37 -37
- metadata +7 -9
- data/lib/yaml_extend/yaml_extend_helper.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0be0858832e50ba9b97682783c3e61550023201916017e95a75277e87766b870
|
4
|
+
data.tar.gz: a27eef2f56b516905246a9dfb19bcc974ed0c8b5554f6b08d0d037df3c00bd1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63a9a94a76eefd6ef9b8cfce70fbaa32e53ee28a1884ddb30ed7df07d702e7731a2fd27a294dc66b64cd4d3978168361f321deedbd64060e06dc6024d9178e77
|
7
|
+
data.tar.gz: d2eb52bc628096d558293fcba275a2bd70de6c623df3c57bce24d7a7b06b4963b5df7c7581be741e17b31a79246493e29c9ed8d441ece95f54f225be0b0405cc
|
data/.gitignore
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
/.vscode/
|
11
|
-
/.idea/
|
12
|
-
*.gem
|
13
|
-
|
14
|
-
# rspec failure tracking
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
/.vscode/
|
11
|
+
/.idea/
|
12
|
+
*.gem
|
13
|
+
|
14
|
+
# rspec failure tracking
|
15
15
|
.rspec_status
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format documentation
|
2
|
-
--color
|
1
|
+
--format documentation
|
2
|
+
--color
|
data/.travis.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.3.3
|
5
|
-
before_install: gem install bundler -v 1.14.6
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.3.3
|
5
|
+
before_install: gem install bundler -v 1.14.6
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,74 +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 yaml_extend.gemspec@mail.magynhard.de. 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/
|
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 yaml_extend.gemspec@mail.magynhard.de. 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
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in yaml_extend.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in yaml_extend.gemspec
|
4
|
+
gemspec
|
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2017 Matthäus Beyrle
|
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 all
|
13
|
-
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 THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017-2021 Matthäus J. N. Beyrle
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,164 +1,181 @@
|
|
1
|
-
# yaml_extend
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
```
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
```
|
130
|
-
|
131
|
-
|
132
|
-
```
|
133
|
-
|
134
|
-
|
135
|
-
```
|
136
|
-
|
137
|
-
|
138
|
-
```
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
1
|
+
# yaml_extend
|
2
|
+
![Gem](https://img.shields.io/gem/v/yaml_extend?color=default&style=plastic&logo=ruby&logoColor=red)
|
3
|
+
![Gem](https://img.shields.io/gem/dt/yaml_extend?color=blue&style=plastic)
|
4
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-gold.svg?style=plastic&logo=mit)](LICENSE)
|
5
|
+
|
6
|
+
> Extends YAML to support file based inheritance.
|
7
|
+
|
8
|
+
That can be very handy to build a configuration hierachy.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'yaml_extend'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle install
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install yaml_extend
|
25
|
+
|
26
|
+
## Common information
|
27
|
+
|
28
|
+
It is possible to build inheritance trees like:
|
29
|
+
```
|
30
|
+
defaults.yml
|
31
|
+
________\_________
|
32
|
+
\ \ \
|
33
|
+
dev.yml int.yml prod.yml
|
34
|
+
```
|
35
|
+
or like this:
|
36
|
+
```
|
37
|
+
fruits.yml vegetables.yml default.yml extensions.yml
|
38
|
+
\ / \ /
|
39
|
+
food.yml merged.yml
|
40
|
+
|
|
41
|
+
another_extended.yml
|
42
|
+
```
|
43
|
+
|
44
|
+
A file can inherit from as many as you want. Trees can be nested as deep as you want.
|
45
|
+
|
46
|
+
YAML files are deep merged, the latest specified child file overwrites the former ones.
|
47
|
+
Array values are merged as well by default. You can specifiy this with the 3rd Parameter.
|
48
|
+
|
49
|
+
The files to inherit from are specified by the key 'extends:' in the YAML file.
|
50
|
+
That key can be customized if you prefer another one.
|
51
|
+
See the examples below.
|
52
|
+
|
53
|
+
## Usage
|
54
|
+
yaml_extend adds the method YAML.ext_load_file to YAML.
|
55
|
+
|
56
|
+
This method works like the original YAML.load_file, by extending it with file inheritance.
|
57
|
+
|
58
|
+
### Examples
|
59
|
+
|
60
|
+
#### Basic Inheritance
|
61
|
+
Given the following both files are defined:
|
62
|
+
|
63
|
+
```yaml
|
64
|
+
# start.yml
|
65
|
+
extends: 'super.yml'
|
66
|
+
data:
|
67
|
+
name: 'Mr. Superman'
|
68
|
+
age: 134
|
69
|
+
favorites:
|
70
|
+
- 'Raspberrys'
|
71
|
+
```
|
72
|
+
|
73
|
+
```yaml
|
74
|
+
# super.yml
|
75
|
+
data:
|
76
|
+
name: 'Unknown'
|
77
|
+
power: 2000
|
78
|
+
favorites:
|
79
|
+
- 'Bananas'
|
80
|
+
- 'Apples'
|
81
|
+
```
|
82
|
+
|
83
|
+
When you then call `ext_load_file`
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
config = YAML.ext_load_file 'start.yml'
|
87
|
+
```
|
88
|
+
|
89
|
+
the returned YAML value results in
|
90
|
+
|
91
|
+
```yaml
|
92
|
+
data:
|
93
|
+
name: 'Mr. Superman'
|
94
|
+
age: 134
|
95
|
+
power: 2000
|
96
|
+
favorites:
|
97
|
+
- 'Bananas'
|
98
|
+
- 'Apples'
|
99
|
+
- 'Raspberrys'
|
100
|
+
```
|
101
|
+
|
102
|
+
#### Inherit from several files
|
103
|
+
|
104
|
+
If you want to inherit from several files, you can specify a list (Array) of files.
|
105
|
+
They are merged from top to bottom, so the latest file "wins" - that means it overwrites duplicate values if they exist with the values in the latest file where they occur.
|
106
|
+
|
107
|
+
```yaml
|
108
|
+
extends:
|
109
|
+
- 'super_file.yml'
|
110
|
+
- 'parent_file.yml'
|
111
|
+
...
|
112
|
+
```
|
113
|
+
|
114
|
+
#### Using custom extend key
|
115
|
+
|
116
|
+
If you don't want to use the default key 'extends:', you can specify your own custom key in two ways.
|
117
|
+
|
118
|
+
```yaml
|
119
|
+
#custom1.yml
|
120
|
+
inherit_from:
|
121
|
+
- 'super_file.yml'
|
122
|
+
foo: 'bar'
|
123
|
+
...
|
124
|
+
```
|
125
|
+
##### 1. Specify by parameter
|
126
|
+
You can specify the key by parameter, this is the way to go if you want to use the different key only once or you use the `ext_load_file` method only once in your application.
|
127
|
+
```ruby
|
128
|
+
config = YAML.ext_load_file 'custom1.yml', 'inherit_from'
|
129
|
+
```
|
130
|
+
##### 2. Global configuration of the key
|
131
|
+
You can specify the key by configuration globally. So you only need to set the key once and not as parameter anymore
|
132
|
+
```ruby
|
133
|
+
YAML.ext_load_key = 'inherit_from'
|
134
|
+
config = YAML.ext_load_file 'custom1.yml'
|
135
|
+
```
|
136
|
+
##### Reset the global key
|
137
|
+
To reset the global inheritance key, you can either set it to nil or call the `reset_load_key` method.
|
138
|
+
```ruby
|
139
|
+
YAML.reset_load_key # more readable
|
140
|
+
YAML.ext_load_key = nil # more explicit
|
141
|
+
```
|
142
|
+
#### Using custom nested extend key
|
143
|
+
```yaml
|
144
|
+
#custom2.yml
|
145
|
+
options:
|
146
|
+
extend_file: 'super_file.yml'
|
147
|
+
database: false
|
148
|
+
foo: 'bar'
|
149
|
+
...
|
150
|
+
```
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
config = YAML.ext_load_file 'custom2.yml', ['options','extend_file']
|
154
|
+
```
|
155
|
+
|
156
|
+
## Documentation
|
157
|
+
```ruby
|
158
|
+
YAML.ext_load_file(yaml_path, inheritance_key='extends', options = {})
|
159
|
+
```
|
160
|
+
- `yaml_path` (String) relative or absolute path to yaml file to inherit from
|
161
|
+
- `inheritance_key` (String) you can overwrite the default key, if you use the default 'extends' already as part of your configuration. The inheritance_key is NOT included, that means it will be deleted, in the final merged file. Default: `'extends'`
|
162
|
+
- `options` (Hash) collection of optional options, including all options of the based `deep_merge` gem
|
163
|
+
- `:preserve_inheritance_key` (Boolean) Preserve inheritance key(s) from resulting yaml, does most time not make sense especially in multiple inheritance - DEFAULT: false
|
164
|
+
- The following options are deep merge options that can be passed by - but the defaults differ from original
|
165
|
+
https://github.com/danielsdeleo/deep_merge#options
|
166
|
+
- `:preserve_unmergeables` (Boolean) Set to true to skip any unmergeable elements from source - DEFAULT: false
|
167
|
+
- `:knockout_prefix` (String) Set to string value to signify prefix which deletes elements from existing element - DEFAULT: nil
|
168
|
+
- `:overwrite_arrays` (Boolean) Set to true if you want to avoid merging arrays - DEFAULT: false
|
169
|
+
- `:sort_merged_arrays` (Boolean) Set to true to sort all arrays that are merged together - DEFAULT: false
|
170
|
+
- `:unpack_arrays` (String) Set to string value to run "Array::join" then "String::split" against all arrays - DEFAULT: nil
|
171
|
+
- `:merge_hash_arrays` (Boolean) Set to true to merge hashes within arrays - DEFAULT: false
|
172
|
+
- `:extend_existing_arrays` (Boolean) Set to true to extend existing arrays, instead of overwriting them - DEFAULT: true
|
173
|
+
- `:merge_nil_values` (Boolean) Set to true to merge nil hash values, overwriting a possibly non-nil value - DEFAULT: false
|
174
|
+
- `:merge_debug` (Boolean) Set to true to get console output of merge process for debugging - DEFAULT: false
|
175
|
+
|
176
|
+
See also rubydoc at [https://www.rubydoc.info/gems/yaml_extend](https://www.rubydoc.info/gems/yaml_extend)
|
177
|
+
|
178
|
+
## Contributing
|
179
|
+
|
180
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/magynhard/yaml_extend. 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.
|
181
|
+
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
#
|
5
|
-
# run default task to see tasks to build and publish gem
|
6
|
-
#
|
7
|
-
task :default do
|
8
|
-
system 'rake --tasks'
|
9
|
-
end
|
10
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
#
|
5
|
+
# run default task to see tasks to build and publish gem
|
6
|
+
#
|
7
|
+
task :default do
|
8
|
+
system 'rake --tasks'
|
9
|
+
end
|
10
|
+
|
11
11
|
RSpec::Core::RakeTask.new(:spec)
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "yaml_extend"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yaml_extend"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class InvalidKeyTypeError < StandardError
|
1
|
+
class InvalidKeyTypeError < StandardError
|
2
2
|
end
|
data/lib/yaml_extend.rb
CHANGED
@@ -1,130 +1,199 @@
|
|
1
|
-
require 'yaml_extend/version'
|
2
|
-
|
3
|
-
require 'yaml'
|
4
|
-
require 'deep_merge/rails_compat'
|
5
|
-
|
6
|
-
require_relative '
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
def self.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
1
|
+
require 'yaml_extend/version'
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'deep_merge/rails_compat'
|
5
|
+
|
6
|
+
require_relative 'custom_errors/invalid_key_type_error'
|
7
|
+
|
8
|
+
#
|
9
|
+
# Extending the YAML library to allow to inherit from another YAML file(s)
|
10
|
+
#
|
11
|
+
|
12
|
+
module YAML
|
13
|
+
# default path in the yaml file where the files to inherit from are defined
|
14
|
+
DEFAULT_INHERITANCE_KEY = 'extends'
|
15
|
+
@@ext_load_key = nil
|
16
|
+
|
17
|
+
DEEP_MERGE_OPTIONS = [
|
18
|
+
:preserve_unmergeables,
|
19
|
+
:knockout_prefix,
|
20
|
+
:overwrite_arrays,
|
21
|
+
:sort_merged_arrays,
|
22
|
+
:unpack_arrays,
|
23
|
+
:merge_hash_arrays,
|
24
|
+
:extend_existing_arrays,
|
25
|
+
:merge_nil_values,
|
26
|
+
:merge_debug,
|
27
|
+
]
|
28
|
+
|
29
|
+
#
|
30
|
+
# Set a custom inheritance key globally once.
|
31
|
+
# So you don't need to specify it on every call of ext_load_file()
|
32
|
+
#
|
33
|
+
# @param key [String|Array<String>|nil] the key in the yaml file, containing the file strings to extend from. Set nil or call #reset_load_key to reset the key.
|
34
|
+
def self.ext_load_key=(key)
|
35
|
+
if key.is_a?(String) || key.is_a?(Array) || key.nil?
|
36
|
+
@@ext_load_key = key
|
37
|
+
else
|
38
|
+
raise "Parameter 'key' must be of type String or Array<String> or nil"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Reset the ext_load_key and use the default settings
|
44
|
+
#
|
45
|
+
def self.reset_load_key()
|
46
|
+
@@ext_load_key = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Extended variant of the YAML.load_file method by providing the
|
51
|
+
# ability to inherit from other YAML file(s)
|
52
|
+
#
|
53
|
+
# @param [String] yaml_path the path to the yaml file to be loaded
|
54
|
+
# @param [String|Array] inheritance_key The key used in the yaml file to extend from another YAML file. Use an Array if you want to use a tree structure key like "options.extends" => ['options','extends']
|
55
|
+
# @param [Hash] options to pass, including deep_merge options as well as
|
56
|
+
# @option options [Boolean] :preserve_inheritance_key Preserve inheritance key(s) from resulting yaml, does most time not make sense especially in multiple inheritance - DEFAULT: false
|
57
|
+
#
|
58
|
+
# deep merge options that can be passed by - but the defaults differ from original
|
59
|
+
# https://github.com/danielsdeleo/deep_merge#options
|
60
|
+
#
|
61
|
+
# @option options [Boolean] :preserve_unmergeables Set to true to skip any unmergeable elements from source - DEFAULT: false
|
62
|
+
# @option options [String] :knockout_prefix Set to string value to signify prefix which deletes elements from existing element - DEFAULT: nil
|
63
|
+
# @option options [Boolean] :overwrite_arrays Set to true if you want to avoid merging arrays - DEFAULT: false
|
64
|
+
# @option options [Boolean] :sort_merged_arrays Set to true to sort all arrays that are merged together - DEFAULT: false
|
65
|
+
# @option options [String] :unpack_arrays Set to string value to run "Array::join" then "String::split" against all arrays - DEFAULT: nil
|
66
|
+
# @option options [Boolean] :merge_hash_arrays Set to true to merge hashes within arrays - DEFAULT: false
|
67
|
+
# @option options [Boolean] :extend_existing_arrays Set to true to extend existing arrays, instead of overwriting them - DEFAULT: true
|
68
|
+
# @option options [Boolean] :merge_nil_values Set to true to merge nil hash values, overwriting a possibly non-nil value - DEFAULT: false
|
69
|
+
# @option options [Boolean] :merge_debug Set to true to get console output of merge process for debugging - DEFAULT: false
|
70
|
+
#
|
71
|
+
# @param [Boolean] options Fallback for backward compatiblity: extend existing arrays instead of replacing them (deep_merge)
|
72
|
+
# @return [Hash] the resulting yaml config
|
73
|
+
#
|
74
|
+
def self.ext_load_file(yaml_path, inheritance_key = nil, options = {})
|
75
|
+
YAML.ext_load_file_recursive(yaml_path, inheritance_key, options, {})
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
#
|
81
|
+
# @param config [Hash] a hash to be merged into the result, usually only recursivly called by the method itself
|
82
|
+
#
|
83
|
+
def self.ext_load_file_recursive(yaml_path, inheritance_key, options = {}, config)
|
84
|
+
# backward compatibility to 1.0.1
|
85
|
+
if options == true || options == false
|
86
|
+
options = {extend_existing_arrays: options}
|
87
|
+
end
|
88
|
+
default_options = {
|
89
|
+
preserve_inheritance_key: false,
|
90
|
+
preserve_unmergeables: false,
|
91
|
+
knockout_prefix: nil,
|
92
|
+
overwrite_arrays: false,
|
93
|
+
sort_merged_arrays: false,
|
94
|
+
unpack_arrays: nil,
|
95
|
+
merge_hash_arrays: false,
|
96
|
+
extend_existing_arrays: true,
|
97
|
+
merge_nil_values: false,
|
98
|
+
merge_debug: false,
|
99
|
+
}
|
100
|
+
options = default_options.merge options
|
101
|
+
private_class_method
|
102
|
+
if inheritance_key.nil?
|
103
|
+
inheritance_key = @@ext_load_key || DEFAULT_INHERITANCE_KEY
|
104
|
+
end
|
105
|
+
total_config = config.clone
|
106
|
+
|
107
|
+
yaml_path = YAML.make_absolute_path yaml_path
|
108
|
+
|
109
|
+
super_config =
|
110
|
+
if yaml_path.match(/(\.erb\.|\.erb$)/)
|
111
|
+
YAML.load(ERB.new(File.read(yaml_path)).result)
|
112
|
+
else
|
113
|
+
YAML.load_file(File.open(yaml_path))
|
114
|
+
end
|
115
|
+
|
116
|
+
super_inheritance_files = yaml_value_by_key inheritance_key, super_config
|
117
|
+
unless options[:preserve_inheritance_key]
|
118
|
+
delete_yaml_key inheritance_key, super_config # we don't merge the super inheritance keys into the base yaml
|
119
|
+
end
|
120
|
+
|
121
|
+
if super_inheritance_files && super_inheritance_files != ''
|
122
|
+
super_inheritance_files = [super_inheritance_files] unless super_inheritance_files.is_a? Array # we support strings as well as arrays of type string to extend from
|
123
|
+
super_inheritance_files.each_with_index do |super_inheritance_file, index|
|
124
|
+
# Extend a YAML path in an absolute directory
|
125
|
+
if YAML.absolute_path?(super_inheritance_file)
|
126
|
+
super_config_path = YAML.make_absolute_path(super_inheritance_file)
|
127
|
+
# Extend a YAML path in a relative directory
|
128
|
+
else
|
129
|
+
super_config_path = File.dirname(yaml_path) + '/' + super_inheritance_file
|
130
|
+
end
|
131
|
+
total_config = YAML.ext_load_file_recursive(super_config_path, inheritance_key, options, total_config)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
deep_merge_options = options.select { |k, v| DEEP_MERGE_OPTIONS.include? k }
|
135
|
+
total_config.deeper_merge!(super_config, deep_merge_options)
|
136
|
+
end
|
137
|
+
|
138
|
+
# some logic to ensure absolute file inheritance as well as
|
139
|
+
# relative file inheritance in yaml files
|
140
|
+
def self.make_absolute_path(file_path)
|
141
|
+
private_class_method
|
142
|
+
return file_path if YAML.absolute_path?(file_path) && File.exist?(file_path)
|
143
|
+
# caller_locations returns the current execution stack
|
144
|
+
# [0] is the call from ext_load_file_recursive,
|
145
|
+
# [1] is inside ext_load_file,
|
146
|
+
# [2] is the exteranl caller of YAML.ext_load_file
|
147
|
+
base_path = File.dirname(caller_locations[2].path)
|
148
|
+
return base_path + '/' + file_path if File.exist? base_path + '/' + file_path # relative path from yaml file
|
149
|
+
return Dir.pwd + '/' + file_path if File.exist? Dir.pwd + '/' + file_path # relative path from project
|
150
|
+
error_message = "Can not find absolute path of '#{file_path}'"
|
151
|
+
unless YAML.absolute_path? file_path
|
152
|
+
error_message += "\nAlso tried:\n- #{base_path + '/' + file_path}\n"\
|
153
|
+
"- #{Dir.pwd + '/' + file_path}\n"
|
154
|
+
end
|
155
|
+
raise error_message
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.absolute_path?(path)
|
159
|
+
private_class_method
|
160
|
+
path.start_with?('/') || # unix like
|
161
|
+
(path.length >= 3 && path[1] == ':') # ms windows
|
162
|
+
end
|
163
|
+
|
164
|
+
# Return the value of the corresponding key
|
165
|
+
# @param key [String|Array]
|
166
|
+
def self.yaml_value_by_key(key, config)
|
167
|
+
return config[key] if key.is_a? String
|
168
|
+
if valid_key_type? key
|
169
|
+
cfg_copy = config.clone
|
170
|
+
key.each do |key|
|
171
|
+
if cfg_copy.nil?
|
172
|
+
return
|
173
|
+
elsif valid_key_type? key
|
174
|
+
cfg_copy = cfg_copy[key]
|
175
|
+
end
|
176
|
+
end
|
177
|
+
cfg_copy
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.valid_key_type?(key)
|
182
|
+
key.is_a?(Array) || key.is_a?(String) ||
|
183
|
+
raise(InvalidKeyTypeError, "Invalid key of type '#{key.class.name}'. Valid types are String and Array.")
|
184
|
+
end
|
185
|
+
|
186
|
+
def self.delete_yaml_key(key, config)
|
187
|
+
return config.delete(key) if key.is_a? String
|
188
|
+
cfg_ref = config
|
189
|
+
last_ref = nil
|
190
|
+
key.each do |key|
|
191
|
+
if valid_key_type?(key) && !cfg_ref[key].nil?
|
192
|
+
last_ref = cfg_ref
|
193
|
+
cfg_ref = cfg_ref[key] unless cfg_ref.nil?
|
194
|
+
end
|
195
|
+
end
|
196
|
+
last_ref.delete key.last unless last_ref.nil?
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
data/lib/yaml_extend/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module YamlExtend
|
2
|
-
VERSION = '
|
3
|
-
end
|
1
|
+
module YamlExtend
|
2
|
+
VERSION = '1.1.0'.freeze
|
3
|
+
end
|
data/yaml_extend.gemspec
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'yaml_extend/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "yaml_extend"
|
8
|
-
spec.version = YamlExtend::VERSION
|
9
|
-
spec.authors = ["Matthäus Beyrle"]
|
10
|
-
spec.email = ["yaml_extend.gemspec@mail.magynhard.de"]
|
11
|
-
|
12
|
-
spec.summary = %q{Extends YAML to support file based inheritance}
|
13
|
-
spec.homepage = "https://github.com/magynhard/yaml_extend"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
-
if spec.respond_to?(:metadata)
|
19
|
-
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
-
else
|
21
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
-
"public gem pushes."
|
23
|
-
end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
f.match(%r{^(test|spec|features)/})
|
27
|
-
end
|
28
|
-
spec.bindir = 'exe'
|
29
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
-
spec.require_paths = ['lib']
|
31
|
-
|
32
|
-
spec.add_dependency 'deep_merge', '~> 1.1'
|
33
|
-
|
34
|
-
spec.add_development_dependency 'bundler', '>= 1.14'
|
35
|
-
spec.add_development_dependency 'rake', '>= 10.0'
|
36
|
-
spec.add_development_dependency 'rspec', '>= 3.0'
|
37
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yaml_extend/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yaml_extend"
|
8
|
+
spec.version = YamlExtend::VERSION
|
9
|
+
spec.authors = ["Matthäus Beyrle"]
|
10
|
+
spec.email = ["yaml_extend.gemspec@mail.magynhard.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{Extends YAML to support file based inheritance}
|
13
|
+
spec.homepage = "https://github.com/magynhard/yaml_extend"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency 'deep_merge', '~> 1.1'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '>= 1.14'
|
35
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '>= 3.0'
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_extend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthäus Beyrle
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email:
|
71
71
|
- yaml_extend.gemspec@mail.magynhard.de
|
72
72
|
executables: []
|
@@ -86,14 +86,13 @@ files:
|
|
86
86
|
- lib/custom_errors/invalid_key_type_error.rb
|
87
87
|
- lib/yaml_extend.rb
|
88
88
|
- lib/yaml_extend/version.rb
|
89
|
-
- lib/yaml_extend/yaml_extend_helper.rb
|
90
89
|
- yaml_extend.gemspec
|
91
90
|
homepage: https://github.com/magynhard/yaml_extend
|
92
91
|
licenses:
|
93
92
|
- MIT
|
94
93
|
metadata:
|
95
94
|
allowed_push_host: https://rubygems.org
|
96
|
-
post_install_message:
|
95
|
+
post_install_message:
|
97
96
|
rdoc_options: []
|
98
97
|
require_paths:
|
99
98
|
- lib
|
@@ -108,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
107
|
- !ruby/object:Gem::Version
|
109
108
|
version: '0'
|
110
109
|
requirements: []
|
111
|
-
|
112
|
-
|
113
|
-
signing_key:
|
110
|
+
rubygems_version: 3.0.8
|
111
|
+
signing_key:
|
114
112
|
specification_version: 4
|
115
113
|
summary: Extends YAML to support file based inheritance
|
116
114
|
test_files: []
|
@@ -1,68 +0,0 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# This class includes a workaround patch, providing a solution of the unaccepted pull request
|
4
|
-
# 'false is not overriden by true if preserve_unmergeables'
|
5
|
-
# https://github.com/danielsdeleo/deep_merge/pull/28
|
6
|
-
#
|
7
|
-
# It ensures, that booleans can be merged correctly, by en- and decoding them to strings, before and after merging
|
8
|
-
# see #encode_boolens and #decode_booleans
|
9
|
-
#
|
10
|
-
|
11
|
-
class YamlExtendHelper
|
12
|
-
|
13
|
-
TRUE_CLASS_ENCODED = '#={TrueClass}=#'
|
14
|
-
FALSE_CLASS_ENCODED = '#={FalseClass}=#'
|
15
|
-
|
16
|
-
def self.encode_booleans(hash)
|
17
|
-
hash.each_with_object({}) do |(k,v),g|
|
18
|
-
g[k] = if v.is_a? Hash
|
19
|
-
YamlExtendHelper.encode_booleans(v)
|
20
|
-
elsif v.is_a? Array
|
21
|
-
v.each_with_index do |av, ai|
|
22
|
-
v[ai] = if av.is_a? Hash
|
23
|
-
YamlExtendHelper.encode_booleans(av)
|
24
|
-
elsif av.is_a? TrueClass
|
25
|
-
TRUE_CLASS_ENCODED
|
26
|
-
elsif av.is_a? FalseClass
|
27
|
-
FALSE_CLASS_ENCODED
|
28
|
-
else
|
29
|
-
av
|
30
|
-
end
|
31
|
-
end
|
32
|
-
elsif v.is_a? TrueClass
|
33
|
-
TRUE_CLASS_ENCODED
|
34
|
-
elsif v.is_a? FalseClass
|
35
|
-
FALSE_CLASS_ENCODED
|
36
|
-
else
|
37
|
-
v
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.decode_booleans(hash)
|
43
|
-
hash.each_with_object({}) do |(k,v),g|
|
44
|
-
g[k] = if v.is_a? Hash
|
45
|
-
YamlExtendHelper.decode_booleans(v)
|
46
|
-
elsif v.is_a? Array
|
47
|
-
v.each_with_index do |av, ai|
|
48
|
-
v[ai] = if av.is_a? Hash
|
49
|
-
YamlExtendHelper.decode_booleans(av)
|
50
|
-
elsif av === TRUE_CLASS_ENCODED
|
51
|
-
true
|
52
|
-
elsif av === FALSE_CLASS_ENCODED
|
53
|
-
false
|
54
|
-
else
|
55
|
-
av
|
56
|
-
end
|
57
|
-
end
|
58
|
-
elsif v === TRUE_CLASS_ENCODED
|
59
|
-
true
|
60
|
-
elsif v === FALSE_CLASS_ENCODED
|
61
|
-
false
|
62
|
-
else
|
63
|
-
v
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|