yaml_extend 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +63 -15
- data/bin/yaml_extend +19 -0
- data/bin/yaml_extend.bat +2 -0
- data/lib/yaml_extend/version.rb +1 -1
- data/lib/yaml_extend.rb +34 -25
- data/yaml_extend.gemspec +2 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e62864fb3a63fe8c957b6fc2a2432eeb67da44c5ff278aa00a4a9935c37fd7fd
|
4
|
+
data.tar.gz: 8156d6c5bd7d13d6753fbaecd86eb07f5e59791f7fa4bb790c0e3b1232408a6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a2f706e91c582c96a03c41567395a783bda1690adaff69866777f5dc77cb70da340055ff27b9a9219bf2cb361c54b52c49c297327d48b315d085d9b1eda900
|
7
|
+
data.tar.gz: c955e1c7c7055fb626fa13b8f77f916107ad67478a76758b3c9251dc0245ed84bed77c431ccce690014a4da6e54d872b0420f788f32b8fde334e127859f1e80e
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# yaml_extend
|
2
|
-
![Gem](https://img.shields.io/gem/v/yaml_extend?color=default&style=plastic&logo=ruby&logoColor=red)
|
3
|
-
![
|
2
|
+
[![Gem](https://img.shields.io/gem/v/yaml_extend?color=default&style=plastic&logo=ruby&logoColor=red)](https://rubygems.org/gems/yaml_extend)
|
3
|
+
![downloads](https://img.shields.io/gem/dt/yaml_extend?color=blue&style=plastic)
|
4
4
|
[![License: MIT](https://img.shields.io/badge/License-MIT-gold.svg?style=plastic&logo=mit)](LICENSE)
|
5
5
|
|
6
6
|
> Extends YAML to support file based inheritance.
|
@@ -9,22 +9,19 @@ That can be very handy to build a configuration hierarchy.
|
|
9
9
|
|
10
10
|
Basic support for ERB (embedded ruby) is included and automatically applied when config files are named `*.erb` or `*.erb.*`.
|
11
11
|
|
12
|
-
|
12
|
+
If you are just doing administration without knowing ruby, you can also just use the command line tool that is included to use this librarys features. Ensure, that [ruby](https://www.ruby-lang.org/) is installed on your system, before following further instructions.
|
13
13
|
|
14
|
-
|
14
|
+
### Contents
|
15
|
+
* [Common information](#common-information)
|
16
|
+
* [Installation](#installation)
|
17
|
+
* [Usage](#usage)
|
18
|
+
* [Command line](#command-line)
|
19
|
+
* [Documentation](#documentation)
|
20
|
+
* [Contributing](#contributing)
|
15
21
|
|
16
|
-
```ruby
|
17
|
-
gem 'yaml_extend'
|
18
|
-
```
|
19
22
|
|
20
|
-
And then execute:
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
Or install it yourself as:
|
25
|
-
|
26
|
-
$ gem install yaml_extend
|
27
|
-
|
24
|
+
<a name="common-information"></a>
|
28
25
|
## Common information
|
29
26
|
|
30
27
|
It is possible to build inheritance trees like:
|
@@ -52,6 +49,32 @@ The files to inherit from are specified by the key 'extends:' in the YAML file.
|
|
52
49
|
That key can be customized if you prefer another one.
|
53
50
|
See the examples below.
|
54
51
|
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
<a name="installation"></a>
|
56
|
+
## Installation
|
57
|
+
### Ruby
|
58
|
+
Add this line to your application's Gemfile:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
gem 'yaml_extend'
|
62
|
+
```
|
63
|
+
|
64
|
+
And then execute:
|
65
|
+
|
66
|
+
$ bundle install
|
67
|
+
|
68
|
+
### Command line
|
69
|
+
If you just want to use the command line then run
|
70
|
+
|
71
|
+
$ gem install yaml_extend
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
<a name="usage"></a>
|
55
78
|
## Usage
|
56
79
|
yaml_extend adds the method YAML.ext_load_file to YAML.
|
57
80
|
|
@@ -155,6 +178,29 @@ foo: 'bar'
|
|
155
178
|
config = YAML.ext_load_file 'custom2.yml', ['options','extend_file']
|
156
179
|
```
|
157
180
|
|
181
|
+
|
182
|
+
|
183
|
+
<a name="command-line"></a>
|
184
|
+
## Command line
|
185
|
+
|
186
|
+
`yaml_extend` is also available on the command line after installation.
|
187
|
+
|
188
|
+
To parse and merge a prepared YAML file, just run
|
189
|
+
|
190
|
+
```
|
191
|
+
yaml_extend path/to/my/yaml_file.yml
|
192
|
+
```
|
193
|
+
|
194
|
+
Usually you might want to put the result into resulting YAML file. So just use the basic command line features to do so:
|
195
|
+
|
196
|
+
|
197
|
+
```
|
198
|
+
yaml_extend path/to/my/yaml_file.yml > combined_yaml.yml
|
199
|
+
```
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
<a name="documentation"></a>
|
158
204
|
## Documentation
|
159
205
|
```ruby
|
160
206
|
YAML.ext_load_file(yaml_path, inheritance_key='extends', options = {})
|
@@ -177,7 +223,9 @@ YAML.ext_load_file(yaml_path, inheritance_key='extends', options = {})
|
|
177
223
|
|
178
224
|
See also rubydoc at [https://www.rubydoc.info/gems/yaml_extend](https://www.rubydoc.info/gems/yaml_extend)
|
179
225
|
|
180
|
-
## Contributing
|
181
226
|
|
227
|
+
|
228
|
+
<a name="documentation"></a>
|
229
|
+
## Contributing
|
182
230
|
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.
|
183
231
|
|
data/bin/yaml_extend
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml_extend'
|
4
|
+
|
5
|
+
arg = ARGV[0]
|
6
|
+
|
7
|
+
if %w[help -h --help].include?(arg) || arg.nil? || arg == ''
|
8
|
+
puts <<-TEXT
|
9
|
+
|
10
|
+
yaml_extend #{YamlExtend::VERSION}
|
11
|
+
https://github.com/magynhard/yaml_extend
|
12
|
+
|
13
|
+
yaml_extend -h --help # show this info
|
14
|
+
yaml_extend <file> # parse and output given file
|
15
|
+
|
16
|
+
TEXT
|
17
|
+
else
|
18
|
+
puts YAML.ext_load_file(arg).to_yaml
|
19
|
+
end
|
data/bin/yaml_extend.bat
ADDED
data/lib/yaml_extend/version.rb
CHANGED
data/lib/yaml_extend.rb
CHANGED
@@ -15,15 +15,15 @@ module YAML
|
|
15
15
|
@@ext_load_key = nil
|
16
16
|
|
17
17
|
DEEP_MERGE_OPTIONS = [
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
27
|
]
|
28
28
|
|
29
29
|
#
|
@@ -86,19 +86,19 @@ module YAML
|
|
86
86
|
yaml_path = yaml_path.to_s
|
87
87
|
# backward compatibility to 1.0.1
|
88
88
|
if options == true || options == false
|
89
|
-
options = {extend_existing_arrays: options}
|
89
|
+
options = { extend_existing_arrays: options }
|
90
90
|
end
|
91
91
|
default_options = {
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
92
|
+
preserve_inheritance_key: false,
|
93
|
+
preserve_unmergeables: false,
|
94
|
+
knockout_prefix: nil,
|
95
|
+
overwrite_arrays: false,
|
96
|
+
sort_merged_arrays: false,
|
97
|
+
unpack_arrays: nil,
|
98
|
+
merge_hash_arrays: false,
|
99
|
+
extend_existing_arrays: true,
|
100
|
+
merge_nil_values: false,
|
101
|
+
merge_debug: false,
|
102
102
|
}
|
103
103
|
options = default_options.merge options
|
104
104
|
private_class_method
|
@@ -111,9 +111,17 @@ module YAML
|
|
111
111
|
|
112
112
|
super_config =
|
113
113
|
if yaml_path.match(/(\.erb\.|\.erb$)/)
|
114
|
-
YAML.unsafe_load
|
114
|
+
if YAML.respond_to? :unsafe_load # backward compatibility for Ruby 3.1 / Psych 4
|
115
|
+
YAML.unsafe_load(ERB.new(File.read(yaml_path)).result)
|
116
|
+
else
|
117
|
+
YAML.load(ERB.new(File.read(yaml_path)).result)
|
118
|
+
end
|
115
119
|
else
|
116
|
-
YAML.unsafe_load_file
|
120
|
+
if YAML.respond_to? :unsafe_load_file # backward compatibility for Ruby 3.1 / Psych 4
|
121
|
+
YAML.unsafe_load_file(File.open(yaml_path))
|
122
|
+
else
|
123
|
+
YAML.load_file(File.open(yaml_path))
|
124
|
+
end
|
117
125
|
end
|
118
126
|
|
119
127
|
super_inheritance_files = yaml_value_by_key inheritance_key, super_config
|
@@ -149,7 +157,8 @@ module YAML
|
|
149
157
|
# [2] is the external caller of YAML.ext_load_file
|
150
158
|
base_path = if defined?(caller_locations)
|
151
159
|
File.dirname(caller_locations[2].path)
|
152
|
-
else
|
160
|
+
else
|
161
|
+
# Fallback for ruby < 2.1.10
|
153
162
|
File.dirname(caller[2])
|
154
163
|
end
|
155
164
|
return base_path + '/' + file_path if File.exist? base_path + '/' + file_path # relative path from yaml file
|
@@ -165,7 +174,7 @@ module YAML
|
|
165
174
|
def self.absolute_path?(path)
|
166
175
|
private_class_method
|
167
176
|
path.start_with?('/') || # unix like
|
168
|
-
|
177
|
+
(path.length >= 3 && path[1] == ':') # ms windows
|
169
178
|
end
|
170
179
|
|
171
180
|
# Return the value of the corresponding key
|
@@ -187,7 +196,7 @@ module YAML
|
|
187
196
|
|
188
197
|
def self.valid_key_type?(key)
|
189
198
|
key.is_a?(Array) || key.is_a?(String) ||
|
190
|
-
|
199
|
+
raise(InvalidKeyTypeError, "Invalid key of type '#{key.class.name}'. Valid types are String and Array.")
|
191
200
|
end
|
192
201
|
|
193
202
|
def self.delete_yaml_key(key, config)
|
data/yaml_extend.gemspec
CHANGED
@@ -6,6 +6,7 @@ require 'yaml_extend/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "yaml_extend"
|
8
8
|
spec.version = YamlExtend::VERSION
|
9
|
+
spec.executables = %w[yaml_extend]
|
9
10
|
spec.authors = ["Matthäus Beyrle"]
|
10
11
|
spec.email = ["yaml_extend.gemspec@mail.magynhard.de"]
|
11
12
|
|
@@ -25,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
25
26
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
27
|
f.match(%r{^(test|spec|features)/})
|
27
28
|
end
|
28
|
-
|
29
|
+
|
29
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
31
|
spec.require_paths = ['lib']
|
31
32
|
|
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: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthäus Beyrle
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -83,6 +83,8 @@ files:
|
|
83
83
|
- Rakefile
|
84
84
|
- bin/console
|
85
85
|
- bin/setup
|
86
|
+
- bin/yaml_extend
|
87
|
+
- bin/yaml_extend.bat
|
86
88
|
- lib/custom_errors/invalid_key_type_error.rb
|
87
89
|
- lib/yaml_extend.rb
|
88
90
|
- lib/yaml_extend/version.rb
|
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
109
|
- !ruby/object:Gem::Version
|
108
110
|
version: '0'
|
109
111
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.1.4
|
111
113
|
signing_key:
|
112
114
|
specification_version: 4
|
113
115
|
summary: Extends YAML to support file based inheritance
|