yaml_extend 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8de4a06253714132d952fcaebc2592ef5410fe38
4
- data.tar.gz: 6fb4e757d42962afa2d85e4fe754a83e0584e204
2
+ SHA256:
3
+ metadata.gz: 709ab41867197b612c61535154fe7e65bad1354c7605417d0fcad1601d45c134
4
+ data.tar.gz: 72f4e212f76e450b96420bb61eeff03aa2e7dc685c6600312ebc767b34987c80
5
5
  SHA512:
6
- metadata.gz: db63a4f3749846aa07412dbc8f95738f9cd43c6aa19ef45dee3b6cd098da66afd16739f3a6e74e0d5cc6188030ec57bd78b874583a8a5ea158350757322a7b8a
7
- data.tar.gz: 9c1a44b1075bab488ce5f02b40ba20cc9afac1d5da487f6dcddf5f7f48acabeb1d980865d5f36c2c1b80658feaffb281096f523a9e74811c234e981081aa2092
6
+ metadata.gz: aebb3c47f6b90557ac6683ed673a036a3b05a469b543c7bf4b3eb07108ff721410a6a5e57b5fa3a643360fe27cf59f3eb99b724a98f8bd483c34159d1d40956e
7
+ data.tar.gz: e15f2449c5c4d93abb0ba1a56cde3928fd06a7219d2cedb6ee20290cabc8fe1c2a27ecd976a04558395b26e26ab42c60f080595ca458c337996861313b532494
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
@@ -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
@@ -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 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.
data/README.md CHANGED
@@ -1,163 +1,163 @@
1
- # yaml_extend
2
-
3
- Extends YAML to support file based inheritance.
4
-
5
- That can be very handy to build a configuration hierachy.
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'yaml_extend'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install yaml_extend
22
-
23
- ## Common information
24
-
25
- It is possible to build inheritance trees like:
26
- ```
27
- defaults.yml
28
- ________\_________
29
- \ \ \
30
- dev.yml int.yml prod.yml
31
- ```
32
- or like this:
33
- ```
34
- default.yml english.yml default.yml german.yml
35
- \ / \ /
36
- uk.yml de.yml
37
- |
38
- at.yml
39
- ```
40
-
41
- A file can inherit from as many as you want. Trees can be nested as deep as you want.
42
-
43
- YAML files are deep merged, the latest specified child file overwrites the former ones.
44
- Array values are merged as well by default. You can specifiy this with the 3rd Parameter.
45
-
46
- The files to inherit from are specified by the key 'extends:' in the YAML file.
47
- That key can be customized if you prefer another one.
48
- See the examples below.
49
-
50
- ## Usage
51
- yaml_extend adds the method YAML.ext_load_file to YAML.
52
-
53
- This method works like the original YAML.load_file, by extending it with file inheritance.
54
-
55
- ### Examples
56
-
57
- #### Basic Inheritance
58
- Given the following both files are defined:
59
-
60
- ```yaml
61
- # start.yml
62
- extends: 'super.yml'
63
- data:
64
- name: 'Mr. Superman'
65
- age: 134
66
- favorites:
67
- - 'Raspberrys'
68
- ```
69
-
70
- ```yaml
71
- # super.yml
72
- data:
73
- name: 'Unknown'
74
- power: 2000
75
- favorites:
76
- - 'Bananas'
77
- - 'Apples'
78
- ```
79
-
80
- When you then call `ext_load_file`
81
-
82
- ```ruby
83
- config = YAML.ext_load_file 'start.yml'
84
- ```
85
-
86
- the returned YAML value results in
87
-
88
- ```yaml
89
- data:
90
- name: 'Mr. Superman'
91
- age: 134
92
- power: 2000
93
- favorites:
94
- - 'Bananas'
95
- - 'Apples'
96
- - 'Raspberrys'
97
- ```
98
-
99
- #### Inherit from several files
100
-
101
- If you want to inherit from several files, you can specify a list (Array) of files.
102
- 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.
103
-
104
- ```yaml
105
- extends:
106
- - 'super_file.yml'
107
- - 'parent_file.yml'
108
- ...
109
- ```
110
-
111
- #### Using custom extend key
112
-
113
- If you don't want to use the default key 'extends:', you can specify your own custom key in two ways.
114
-
115
- ```yaml
116
- #custom1.yml
117
- inherit_from:
118
- - 'super_file.yml'
119
- foo: 'bar'
120
- ...
121
- ```
122
- ##### 1. Specify by parameter
123
- 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.
124
- ```ruby
125
- config = YAML.ext_load_file 'custom1.yml', 'inherit_from'
126
- ```
127
- ##### 2. Global configuration of the key
128
- You can specify the key by configuration globally. So you only need to set the key once and not as parameter anymore
129
- ```ruby
130
- YAML.ext_load_key = 'inherit_from'
131
- config = YAML.ext_load_file 'custom1.yml'
132
- ```
133
- ##### Reset the global key
134
- To reset the global inheritance key, you can either set it to nil or call the `reset_load_key` method.
135
- ```ruby
136
- YAML.reset_load_key # more readable
137
- YAML.ext_load_key = nil # more explicit
138
- ```
139
- #### Using custom nested extend key
140
- ```yaml
141
- #custom2.yml
142
- options:
143
- extend_file: 'super_file.yml'
144
- database: false
145
- foo: 'bar'
146
- ...
147
- ```
148
-
149
- ```ruby
150
- config = YAML.ext_load_file 'custom2.yml', ['options','extend_file']
151
- ```
152
-
153
- ## Documentation
154
- YAML.ext_load_file(yaml_path, inheritance_key='extends', extend_existing_arrays=true)
155
-
156
- - *yaml_path* relative or absolute path to yaml file to inherit from
157
- - *inheritance_key* 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'
158
- - *extend_existing_arrays* Extends existing arrays in yaml structure instead of replacing them. Default: true
159
-
160
- ## Contributing
161
-
162
- 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.
163
-
1
+ # yaml_extend
2
+
3
+ Extends YAML to support file based inheritance.
4
+
5
+ That can be very handy to build a configuration hierachy.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'yaml_extend'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yaml_extend
22
+
23
+ ## Common information
24
+
25
+ It is possible to build inheritance trees like:
26
+ ```
27
+ defaults.yml
28
+ ________\_________
29
+ \ \ \
30
+ dev.yml int.yml prod.yml
31
+ ```
32
+ or like this:
33
+ ```
34
+ default.yml english.yml default.yml german.yml
35
+ \ / \ /
36
+ uk.yml de.yml
37
+ |
38
+ at.yml
39
+ ```
40
+
41
+ A file can inherit from as many as you want. Trees can be nested as deep as you want.
42
+
43
+ YAML files are deep merged, the latest specified child file overwrites the former ones.
44
+ Array values are merged as well by default. You can specifiy this with the 3rd Parameter.
45
+
46
+ The files to inherit from are specified by the key 'extends:' in the YAML file.
47
+ That key can be customized if you prefer another one.
48
+ See the examples below.
49
+
50
+ ## Usage
51
+ yaml_extend adds the method YAML.ext_load_file to YAML.
52
+
53
+ This method works like the original YAML.load_file, by extending it with file inheritance.
54
+
55
+ ### Examples
56
+
57
+ #### Basic Inheritance
58
+ Given the following both files are defined:
59
+
60
+ ```yaml
61
+ # start.yml
62
+ extends: 'super.yml'
63
+ data:
64
+ name: 'Mr. Superman'
65
+ age: 134
66
+ favorites:
67
+ - 'Raspberrys'
68
+ ```
69
+
70
+ ```yaml
71
+ # super.yml
72
+ data:
73
+ name: 'Unknown'
74
+ power: 2000
75
+ favorites:
76
+ - 'Bananas'
77
+ - 'Apples'
78
+ ```
79
+
80
+ When you then call `ext_load_file`
81
+
82
+ ```ruby
83
+ config = YAML.ext_load_file 'start.yml'
84
+ ```
85
+
86
+ the returned YAML value results in
87
+
88
+ ```yaml
89
+ data:
90
+ name: 'Mr. Superman'
91
+ age: 134
92
+ power: 2000
93
+ favorites:
94
+ - 'Bananas'
95
+ - 'Apples'
96
+ - 'Raspberrys'
97
+ ```
98
+
99
+ #### Inherit from several files
100
+
101
+ If you want to inherit from several files, you can specify a list (Array) of files.
102
+ 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.
103
+
104
+ ```yaml
105
+ extends:
106
+ - 'super_file.yml'
107
+ - 'parent_file.yml'
108
+ ...
109
+ ```
110
+
111
+ #### Using custom extend key
112
+
113
+ If you don't want to use the default key 'extends:', you can specify your own custom key in two ways.
114
+
115
+ ```yaml
116
+ #custom1.yml
117
+ inherit_from:
118
+ - 'super_file.yml'
119
+ foo: 'bar'
120
+ ...
121
+ ```
122
+ ##### 1. Specify by parameter
123
+ 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.
124
+ ```ruby
125
+ config = YAML.ext_load_file 'custom1.yml', 'inherit_from'
126
+ ```
127
+ ##### 2. Global configuration of the key
128
+ You can specify the key by configuration globally. So you only need to set the key once and not as parameter anymore
129
+ ```ruby
130
+ YAML.ext_load_key = 'inherit_from'
131
+ config = YAML.ext_load_file 'custom1.yml'
132
+ ```
133
+ ##### Reset the global key
134
+ To reset the global inheritance key, you can either set it to nil or call the `reset_load_key` method.
135
+ ```ruby
136
+ YAML.reset_load_key # more readable
137
+ YAML.ext_load_key = nil # more explicit
138
+ ```
139
+ #### Using custom nested extend key
140
+ ```yaml
141
+ #custom2.yml
142
+ options:
143
+ extend_file: 'super_file.yml'
144
+ database: false
145
+ foo: 'bar'
146
+ ...
147
+ ```
148
+
149
+ ```ruby
150
+ config = YAML.ext_load_file 'custom2.yml', ['options','extend_file']
151
+ ```
152
+
153
+ ## Documentation
154
+ YAML.ext_load_file(yaml_path, inheritance_key='extends', extend_existing_arrays=true)
155
+
156
+ - *yaml_path* relative or absolute path to yaml file to inherit from
157
+ - *inheritance_key* 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'
158
+ - *extend_existing_arrays* Extends existing arrays in yaml structure instead of replacing them. Default: true
159
+
160
+ ## Contributing
161
+
162
+ 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.
163
+
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)
@@ -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
@@ -1,137 +1,143 @@
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
- # Set a custom inheritance key globally once.
18
- # So you don't need to specify it on every call of ext_load_file()
19
- #
20
- # @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.
21
- def self.ext_load_key=(key)
22
- if key.is_a?(String) || key.is_a?(Array) || key.nil?
23
- @@ext_load_key = key
24
- else
25
- raise "Parameter 'key' must be of type String or Array<String> or nil"
26
- end
27
- end
28
-
29
- #
30
- # Reset the ext_load_key and use the default settings
31
- #
32
- def self.reset_load_key()
33
- @@ext_load_key = nil
34
- end
35
-
36
- #
37
- # Extended variant of the YAML.load_file method by providing the
38
- # ability to inherit from other YAML file(s)
39
- #
40
- # @param yaml_path [String] the path to the yaml file to be loaded
41
- # @param inheritance_key [String|Array] 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']
42
- # @param extend_existing_arrays [Boolean] extend existing arrays instead of replacing them
43
- # @return [Hash] the resulting yaml config
44
- #
45
- def self.ext_load_file(yaml_path, inheritance_key=nil, extend_existing_arrays=true)
46
- YAML.ext_load_file_recursive(yaml_path, inheritance_key, extend_existing_arrays, {})
47
- end
48
-
49
- private
50
-
51
- #
52
- # @param config [Hash] a hash to be merged into the result, usually only recursivly called by the method itself
53
- #
54
- def self.ext_load_file_recursive(yaml_path, inheritance_key, extend_existing_arrays, config)
55
- private_class_method
56
- if inheritance_key.nil?
57
- inheritance_key = @@ext_load_key || DEFAULT_INHERITANCE_KEY
58
- end
59
- total_config = config.clone
60
-
61
- yaml_path = YAML.make_absolute_path yaml_path
62
- super_config = YAML.load_file(File.open(yaml_path))
63
- super_inheritance_files = yaml_value_by_key inheritance_key, super_config
64
- delete_yaml_key inheritance_key, super_config # we don't merge the super inheritance keys into the base yaml
65
-
66
- if super_inheritance_files && super_inheritance_files != ''
67
- 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
68
- super_inheritance_files.each_with_index do |super_inheritance_file, index|
69
- super_config_path = File.dirname(yaml_path) + '/' + super_inheritance_file
70
- total_config = YAML.ext_load_file_recursive(super_config_path, inheritance_key, extend_existing_arrays, total_config)
71
- end
72
- end
73
- total_config.deeper_merge!(super_config, extend_existing_arrays: extend_existing_arrays)
74
- end
75
-
76
- # some logic to ensure absolute file inheritance as well as
77
- # relative file inheritance in yaml files
78
- def self.make_absolute_path(file_path)
79
- private_class_method
80
- return file_path if YAML.absolute_path?(file_path) && File.exist?(file_path)
81
- # caller_locations returns the current execution stack
82
- # [0] is the call from ext_load_file_recursive,
83
- # [1] is inside ext_load_file,
84
- # [2] is the exteranl caller of YAML.ext_load_file
85
- base_path = File.dirname(caller_locations[2].path)
86
- return base_path + '/' + file_path if File.exist? base_path + '/' + file_path # relative path from yaml file
87
- return Dir.pwd + '/' + file_path if File.exist? Dir.pwd + '/' + file_path # relative path from project
88
- error_message = "Can not find absolute path of '#{file_path}'"
89
- unless YAML.absolute_path? file_path
90
- error_message += "\nAlso tried:\n- #{base_path + '/' + file_path}\n"\
91
- "- #{Dir.pwd + '/' + file_path}\n"
92
- end
93
- raise error_message
94
- end
95
-
96
- def self.absolute_path?(path)
97
- private_class_method
98
- path.start_with?('/') || # unix like
99
- (path.length >= 3 && path[1] == ':') # ms windows
100
- end
101
-
102
- # Return the value of the corresponding key
103
- # @param key [String|Array]
104
- def self.yaml_value_by_key(key, config)
105
- return config[key] if key.is_a? String
106
- if valid_key_type? key
107
- cfg_copy = config.clone
108
- key.each do |key|
109
- if cfg_copy.nil?
110
- return
111
- elsif valid_key_type? key
112
- cfg_copy = cfg_copy[key]
113
- end
114
- end
115
- cfg_copy
116
- end
117
- end
118
-
119
- def self.valid_key_type?(key)
120
- key.is_a?(Array) || key.is_a?(String) ||
121
- raise(InvalidKeyTypeError,"Invalid key of type '#{key.class.name}'. Valid types are String and Array.")
122
- end
123
-
124
- def self.delete_yaml_key(key, config)
125
- return config.delete(key) if key.is_a? String
126
- cfg_ref = config
127
- last_ref = nil
128
- key.each do |key|
129
- if valid_key_type?(key) && !cfg_ref[key].nil?
130
- last_ref = cfg_ref
131
- cfg_ref = cfg_ref[key] unless cfg_ref.nil?
132
- end
133
- end
134
- last_ref.delete key.last unless last_ref.nil?
135
- end
136
-
137
- 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
+ # Set a custom inheritance key globally once.
18
+ # So you don't need to specify it on every call of ext_load_file()
19
+ #
20
+ # @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.
21
+ def self.ext_load_key=(key)
22
+ if key.is_a?(String) || key.is_a?(Array) || key.nil?
23
+ @@ext_load_key = key
24
+ else
25
+ raise "Parameter 'key' must be of type String or Array<String> or nil"
26
+ end
27
+ end
28
+
29
+ #
30
+ # Reset the ext_load_key and use the default settings
31
+ #
32
+ def self.reset_load_key()
33
+ @@ext_load_key = nil
34
+ end
35
+
36
+ #
37
+ # Extended variant of the YAML.load_file method by providing the
38
+ # ability to inherit from other YAML file(s)
39
+ #
40
+ # @param yaml_path [String] the path to the yaml file to be loaded
41
+ # @param inheritance_key [String|Array] 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']
42
+ # @param extend_existing_arrays [Boolean] extend existing arrays instead of replacing them
43
+ # @return [Hash] the resulting yaml config
44
+ #
45
+ def self.ext_load_file(yaml_path, inheritance_key=nil, extend_existing_arrays=true)
46
+ YAML.ext_load_file_recursive(yaml_path, inheritance_key, extend_existing_arrays, {})
47
+ end
48
+
49
+ private
50
+
51
+ #
52
+ # @param config [Hash] a hash to be merged into the result, usually only recursivly called by the method itself
53
+ #
54
+ def self.ext_load_file_recursive(yaml_path, inheritance_key, extend_existing_arrays, config)
55
+ private_class_method
56
+ if inheritance_key.nil?
57
+ inheritance_key = @@ext_load_key || DEFAULT_INHERITANCE_KEY
58
+ end
59
+ total_config = config.clone
60
+
61
+ yaml_path = YAML.make_absolute_path yaml_path
62
+ super_config = YAML.load_file(File.open(yaml_path))
63
+ super_inheritance_files = yaml_value_by_key inheritance_key, super_config
64
+ delete_yaml_key inheritance_key, super_config # we don't merge the super inheritance keys into the base yaml
65
+
66
+ if super_inheritance_files && super_inheritance_files != ''
67
+ 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
68
+ super_inheritance_files.each_with_index do |super_inheritance_file, index|
69
+ # Extend a YAML path in an absolute directory
70
+ if YAML.absolute_path?(super_inheritance_file)
71
+ super_config_path = YAML.make_absolute_path(super_inheritance_file)
72
+ # Extend a YAML path in a relative directory
73
+ else
74
+ super_config_path = File.dirname(yaml_path) + '/' + super_inheritance_file
75
+ end
76
+ total_config = YAML.ext_load_file_recursive(super_config_path, inheritance_key, extend_existing_arrays, total_config)
77
+ end
78
+ end
79
+ total_config.deeper_merge!(super_config, extend_existing_arrays: extend_existing_arrays)
80
+ end
81
+
82
+ # some logic to ensure absolute file inheritance as well as
83
+ # relative file inheritance in yaml files
84
+ def self.make_absolute_path(file_path)
85
+ private_class_method
86
+ return file_path if YAML.absolute_path?(file_path) && File.exist?(file_path)
87
+ # caller_locations returns the current execution stack
88
+ # [0] is the call from ext_load_file_recursive,
89
+ # [1] is inside ext_load_file,
90
+ # [2] is the exteranl caller of YAML.ext_load_file
91
+ base_path = File.dirname(caller_locations[2].path)
92
+ return base_path + '/' + file_path if File.exist? base_path + '/' + file_path # relative path from yaml file
93
+ return Dir.pwd + '/' + file_path if File.exist? Dir.pwd + '/' + file_path # relative path from project
94
+ error_message = "Can not find absolute path of '#{file_path}'"
95
+ unless YAML.absolute_path? file_path
96
+ error_message += "\nAlso tried:\n- #{base_path + '/' + file_path}\n"\
97
+ "- #{Dir.pwd + '/' + file_path}\n"
98
+ end
99
+ raise error_message
100
+ end
101
+
102
+ def self.absolute_path?(path)
103
+ private_class_method
104
+ path.start_with?('/') || # unix like
105
+ (path.length >= 3 && path[1] == ':') # ms windows
106
+ end
107
+
108
+ # Return the value of the corresponding key
109
+ # @param key [String|Array]
110
+ def self.yaml_value_by_key(key, config)
111
+ return config[key] if key.is_a? String
112
+ if valid_key_type? key
113
+ cfg_copy = config.clone
114
+ key.each do |key|
115
+ if cfg_copy.nil?
116
+ return
117
+ elsif valid_key_type? key
118
+ cfg_copy = cfg_copy[key]
119
+ end
120
+ end
121
+ cfg_copy
122
+ end
123
+ end
124
+
125
+ def self.valid_key_type?(key)
126
+ key.is_a?(Array) || key.is_a?(String) ||
127
+ raise(InvalidKeyTypeError,"Invalid key of type '#{key.class.name}'. Valid types are String and Array.")
128
+ end
129
+
130
+ def self.delete_yaml_key(key, config)
131
+ return config.delete(key) if key.is_a? String
132
+ cfg_ref = config
133
+ last_ref = nil
134
+ key.each do |key|
135
+ if valid_key_type?(key) && !cfg_ref[key].nil?
136
+ last_ref = cfg_ref
137
+ cfg_ref = cfg_ref[key] unless cfg_ref.nil?
138
+ end
139
+ end
140
+ last_ref.delete key.last unless last_ref.nil?
141
+ end
142
+
143
+ end
@@ -1,3 +1,3 @@
1
- module YamlExtend
2
- VERSION = '1.0.0'.freeze
3
- end
1
+ module YamlExtend
2
+ VERSION = '1.0.1'.freeze
3
+ end
@@ -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: 1.0.0
4
+ version: 1.0.1
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: 2019-12-05 00:00:00.000000000 Z
11
+ date: 2020-07-22 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: []
@@ -92,7 +92,7 @@ licenses:
92
92
  - MIT
93
93
  metadata:
94
94
  allowed_push_host: https://rubygems.org
95
- post_install_message:
95
+ post_install_message:
96
96
  rdoc_options: []
97
97
  require_paths:
98
98
  - lib
@@ -107,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.5.2
112
- signing_key:
110
+ rubygems_version: 3.1.3
111
+ signing_key:
113
112
  specification_version: 4
114
113
  summary: Extends YAML to support file based inheritance
115
114
  test_files: []