yaml_extend 0.2.3 → 0.2.4

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
2
  SHA256:
3
- metadata.gz: 805447b25c0ac209e4c59d10d8c9f5dc2432a7271aafd0e9d9f16ccd984e6522
4
- data.tar.gz: 654ad7daaec70841729bcef0131f4e29108456a8fdd17fc9898eedbd89f69e4f
3
+ metadata.gz: c1e9451593e33ce34c29b421877a77b8311f1b9e12ec5e32f031d191b0e8517a
4
+ data.tar.gz: 50d624f0bcc5f0b859e83ce39b8752de9e0fb0a7b74d64327c0af79e008fcba4
5
5
  SHA512:
6
- metadata.gz: 5af7d94d3783ffdb7a3c28fe5e2459d2c3423197f25939bfe3d5f2e88da1db044e94e38d08e8751ca165d4c89b656adc1f6a2104f5065eade9d2d6c34e59cb07
7
- data.tar.gz: ebd14878f223d0bdb4f6c2a480e1a3d9ac91131f98db8202d4a4dda35347ad24457e0b86cc57765b48bb8a1ce02742280207bd882e1516a6d80728234d4b28df
6
+ metadata.gz: 39f2e58240eda0ef6b12de0631b7d9965b1cd85c36401553dafdc90de7c2a6c57c6f982aaae30c5bf7f7da325e963c12ddcfc787de506569ae70bd8778aec4a3
7
+ data.tar.gz: 7012a0c7207557756926bc7a86ed36917717cef25d9eb036633f96293b8f7c58947e7d8eeafa37731b3cd948de014180c23e278e223935d01fac77596c8c5716
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 m.beyrle@walz.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,156 +1,156 @@
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
- default.yml english.yml default.yml german.yml de.yml
28
- \ / \ / |
29
- uk.yml de.yml at.yml
30
- ```
31
-
32
- A file can inherit from as many as you want. Trees can be nested as deep as you want.
33
-
34
- YAML files are deep merged, the latest specified child file overwrites the former ones.
35
- Array values are merged as well by default. You can specifiy this with the 3rd Parameter.
36
-
37
- The files to inherit from are specified by the key 'extends:' in the YAML file.
38
- That key can be customized if you prefer another one.
39
- See the examples below.
40
-
41
- ## Usage
42
- yaml_extend adds the method YAML#ext_load_file to YAML.
43
-
44
- This method works like the original YAML#load_file, by extending it with file inheritance.
45
-
46
- ### Examples
47
-
48
- #### Basic Inheritance
49
- Given the following both files are defined:
50
-
51
- ```yaml
52
- # start.yml
53
- extends: 'super.yml'
54
- data:
55
- name: 'Mr. Superman'
56
- age: 134
57
- favorites:
58
- - 'Raspberrys'
59
- ```
60
-
61
- ```yaml
62
- # super.yml
63
- data:
64
- name: 'Unknown'
65
- power: 2000
66
- favorites:
67
- - 'Bananas'
68
- - 'Apples'
69
- ```
70
-
71
- When you then call #ext_load_file
72
-
73
- ```ruby
74
- YAML.ext_load_file 'start.yml'
75
- ```
76
-
77
- the returned YAML value results in
78
-
79
- ```yaml
80
- data:
81
- name: 'Mr. Superman'
82
- age: 134
83
- power: 2000
84
- favorites:
85
- - 'Bananas'
86
- - 'Apples'
87
- - 'Raspberrys'
88
- ```
89
-
90
- #### Inherit from several files
91
-
92
- If you want to inherit from several files, you can specify a list (Array) of files.
93
- 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.
94
-
95
- ```yaml
96
- extends:
97
- - 'super_file.yml'
98
- - 'parent_file.yml'
99
- ...
100
- ```
101
-
102
- #### Using custom extend key
103
-
104
- If you don't want to use the default key 'extends:', you can specify your own custom key in two ways.
105
-
106
- ```yaml
107
- #custom1.yml
108
- inherit_from:
109
- - 'super_file.yml'
110
- foo: 'bar'
111
- ...
112
- ```
113
- ##### 1. Specify by parameter
114
- 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.
115
- ```ruby
116
- YAML.ext_load_file 'custom1.yml', 'inherit_from'
117
- ```
118
- ##### 2. Global configuration of the key
119
- You can specify the key by configuration globally. So you only need to set the key once and not as parameter anymore
120
- ```ruby
121
- YAML.ext_load_key = 'inherit_from'
122
- YAML.ext_load_file 'custom1.yml'
123
- YAML.ext_load_file 'custom2.yml'
124
- ```
125
- ##### Reset the global key
126
- To reset the global inheritance key, you can either set it to nil or call the #reset_load_key method.
127
- ```ruby
128
- YAML.reset_load_key # more readable
129
- YAML.ext_load_key = nil # more explicit
130
- ```
131
- #### Using custom nested extend key
132
- ```yaml
133
- #custom2.yml
134
- options:
135
- extend_file: 'super_file.yml'
136
- database: false
137
- foo: 'bar'
138
- ...
139
- ```
140
-
141
- ```ruby
142
- YAML.ext_load_file 'custom2.yml', ['options','extend_file']
143
- ```
144
-
145
- ## Documentation
146
- YAML#ext_load_file(yaml_path, inheritance_key='extends', extend_existing_arrays=true, config = {})
147
-
148
- - *yaml_path* relative or absolute path to yaml file to inherit from
149
- - *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'
150
- - *extend_existing_arrays* Extends existing arrays in yaml structure instead of replacing them. Default: true
151
- - *config* only intended to be used by the method itself due recursive algorithm
152
-
153
- ## Contributing
154
-
155
- 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.
156
-
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
+ default.yml english.yml default.yml german.yml de.yml
28
+ \ / \ / |
29
+ uk.yml de.yml at.yml
30
+ ```
31
+
32
+ A file can inherit from as many as you want. Trees can be nested as deep as you want.
33
+
34
+ YAML files are deep merged, the latest specified child file overwrites the former ones.
35
+ Array values are merged as well by default. You can specifiy this with the 3rd Parameter.
36
+
37
+ The files to inherit from are specified by the key 'extends:' in the YAML file.
38
+ That key can be customized if you prefer another one.
39
+ See the examples below.
40
+
41
+ ## Usage
42
+ yaml_extend adds the method YAML#ext_load_file to YAML.
43
+
44
+ This method works like the original YAML#load_file, by extending it with file inheritance.
45
+
46
+ ### Examples
47
+
48
+ #### Basic Inheritance
49
+ Given the following both files are defined:
50
+
51
+ ```yaml
52
+ # start.yml
53
+ extends: 'super.yml'
54
+ data:
55
+ name: 'Mr. Superman'
56
+ age: 134
57
+ favorites:
58
+ - 'Raspberrys'
59
+ ```
60
+
61
+ ```yaml
62
+ # super.yml
63
+ data:
64
+ name: 'Unknown'
65
+ power: 2000
66
+ favorites:
67
+ - 'Bananas'
68
+ - 'Apples'
69
+ ```
70
+
71
+ When you then call #ext_load_file
72
+
73
+ ```ruby
74
+ YAML.ext_load_file 'start.yml'
75
+ ```
76
+
77
+ the returned YAML value results in
78
+
79
+ ```yaml
80
+ data:
81
+ name: 'Mr. Superman'
82
+ age: 134
83
+ power: 2000
84
+ favorites:
85
+ - 'Bananas'
86
+ - 'Apples'
87
+ - 'Raspberrys'
88
+ ```
89
+
90
+ #### Inherit from several files
91
+
92
+ If you want to inherit from several files, you can specify a list (Array) of files.
93
+ 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.
94
+
95
+ ```yaml
96
+ extends:
97
+ - 'super_file.yml'
98
+ - 'parent_file.yml'
99
+ ...
100
+ ```
101
+
102
+ #### Using custom extend key
103
+
104
+ If you don't want to use the default key 'extends:', you can specify your own custom key in two ways.
105
+
106
+ ```yaml
107
+ #custom1.yml
108
+ inherit_from:
109
+ - 'super_file.yml'
110
+ foo: 'bar'
111
+ ...
112
+ ```
113
+ ##### 1. Specify by parameter
114
+ 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.
115
+ ```ruby
116
+ YAML.ext_load_file 'custom1.yml', 'inherit_from'
117
+ ```
118
+ ##### 2. Global configuration of the key
119
+ You can specify the key by configuration globally. So you only need to set the key once and not as parameter anymore
120
+ ```ruby
121
+ YAML.ext_load_key = 'inherit_from'
122
+ YAML.ext_load_file 'custom1.yml'
123
+ YAML.ext_load_file 'custom2.yml'
124
+ ```
125
+ ##### Reset the global key
126
+ To reset the global inheritance key, you can either set it to nil or call the #reset_load_key method.
127
+ ```ruby
128
+ YAML.reset_load_key # more readable
129
+ YAML.ext_load_key = nil # more explicit
130
+ ```
131
+ #### Using custom nested extend key
132
+ ```yaml
133
+ #custom2.yml
134
+ options:
135
+ extend_file: 'super_file.yml'
136
+ database: false
137
+ foo: 'bar'
138
+ ...
139
+ ```
140
+
141
+ ```ruby
142
+ YAML.ext_load_file 'custom2.yml', ['options','extend_file']
143
+ ```
144
+
145
+ ## Documentation
146
+ YAML#ext_load_file(yaml_path, inheritance_key='extends', extend_existing_arrays=true, config = {})
147
+
148
+ - *yaml_path* relative or absolute path to yaml file to inherit from
149
+ - *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'
150
+ - *extend_existing_arrays* Extends existing arrays in yaml structure instead of replacing them. Default: true
151
+ - *config* only intended to be used by the method itself due recursive algorithm
152
+
153
+ ## Contributing
154
+
155
+ 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.
156
+
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,130 +1,130 @@
1
- require 'yaml_extend/version'
2
-
3
- require 'yaml'
4
- require 'deep_merge/rails_compat'
5
-
6
- require_relative 'yaml_extend/yaml_extend_helper'
7
-
8
- require_relative 'custom_errors/invalid_key_type_error'
9
-
10
- #
11
- # Extending the YAML library to allow to inherit from another YAML file(s)
12
- #
13
-
14
- module YAML
15
- # default path in the yaml file where the files to inherit from are defined
16
- DEFAULT_INHERITANCE_KEY = 'extends'
17
- @@ext_load_key = nil
18
- #
19
- # Set a custom inheritance key globally once.
20
- # So you don't need to specify it on every call of ext_load_file()
21
- #
22
- # @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.
23
- def self.ext_load_key=(key)
24
- if key.is_a?(String) || key.is_a?(Array) || key.nil?
25
- @@ext_load_key = key
26
- else
27
- raise "Parameter 'key' must be of type String or Array<String> or nil"
28
- end
29
- end
30
-
31
- #
32
- # Reset the ext_load_key and use the default settings
33
- #
34
- def self.reset_load_key()
35
- @@ext_load_key = nil
36
- end
37
- #
38
- # Extended variant of the #load_file method by providing the
39
- # ability to inherit from other YAML file(s)
40
- #
41
- # @param yaml_path [String] the path to the yaml file to be loaded
42
- # @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']
43
- # @param extend_existing_arrays [Boolean] extend existing arrays instead of replacing them
44
- # @param config [Hash] a hash to be merged into the result, usually only recursivly called by the method itself
45
- #
46
- # @return [Hash] the resulting yaml config
47
- #
48
- def self.ext_load_file(yaml_path, inheritance_key=nil, extend_existing_arrays=true, config = {})
49
- if inheritance_key.nil?
50
- inheritance_key = @@ext_load_key || DEFAULT_INHERITANCE_KEY
51
- end
52
- total_config ||= {}
53
- yaml_path = YAML.make_absolute_path yaml_path
54
- super_config = YamlExtendHelper.encode_booleans YAML.load_file(File.open(yaml_path))
55
- super_inheritance_files = yaml_value_by_key inheritance_key, super_config
56
- delete_yaml_key inheritance_key, super_config # we don't merge the super inheritance keys into the base yaml
57
- merged_config = config.clone.deeper_merge(super_config, extend_existing_arrays: extend_existing_arrays)
58
- if super_inheritance_files && super_inheritance_files != ''
59
- 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
60
- super_inheritance_files.each_with_index do |super_inheritance_file, index|
61
- super_config_path = File.dirname(yaml_path) + '/' + super_inheritance_file
62
- total_config = YamlExtendHelper.encode_booleans YAML.ext_load_file(super_config_path, inheritance_key, extend_existing_arrays, total_config.deeper_merge(merged_config, extend_existing_arrays: extend_existing_arrays))
63
- end
64
- YamlExtendHelper.decode_booleans total_config
65
- else
66
- delete_yaml_key inheritance_key, merged_config
67
- YamlExtendHelper.decode_booleans merged_config
68
- end
69
- end
70
-
71
- private
72
-
73
- # some logic to ensure absolute file inheritance as well as
74
- # relative file inheritance in yaml files
75
- def self.make_absolute_path(file_path)
76
- private_class_method
77
- return file_path if YAML.absolute_path?(file_path) && File.exist?(file_path)
78
- base_path = File.dirname(caller_locations[1].path)
79
- return base_path + '/' + file_path if File.exist? base_path + '/' + file_path # relative path from yaml file
80
- return Dir.pwd + '/' + file_path if File.exist? Dir.pwd + '/' + file_path # relative path from project
81
- error_message = "Can not find absolute path of '#{file_path}'"
82
- unless YAML.absolute_path? file_path
83
- error_message += "\nAlso tried:\n- #{base_path + '/' + file_path}\n"\
84
- "- #{Dir.pwd + '/' + file_path}\n"
85
- end
86
- raise error_message
87
- end
88
-
89
- def self.absolute_path?(path)
90
- private_class_method
91
- path.start_with?('/') || # unix like
92
- (path.length >= 3 && path[1] == ':') # ms windows
93
- end
94
-
95
- # Return the value of the corresponding key
96
- # @param key [String|Array]
97
- def self.yaml_value_by_key(key, config)
98
- return config[key] if key.is_a? String
99
- if valid_key_type? key
100
- cfg_copy = config.clone
101
- key.each do |key|
102
- if cfg_copy.nil?
103
- return
104
- elsif valid_key_type? key
105
- cfg_copy = cfg_copy[key]
106
- end
107
- end
108
- cfg_copy
109
- end
110
- end
111
-
112
- def self.valid_key_type?(key)
113
- key.is_a?(Array) || key.is_a?(String) ||
114
- raise(InvalidKeyTypeError,"Invalid key of type '#{key.class.name}'. Valid types are String and Array.")
115
- end
116
-
117
- def self.delete_yaml_key(key, config)
118
- return config.delete(key) if key.is_a? String
119
- cfg_ref = config
120
- last_ref = nil
121
- key.each do |key|
122
- if valid_key_type?(key) && !cfg_ref[key].nil?
123
- last_ref = cfg_ref
124
- cfg_ref = cfg_ref[key] unless cfg_ref.nil?
125
- end
126
- end
127
- last_ref.delete key.last unless last_ref.nil?
128
- end
129
-
130
- end
1
+ require 'yaml_extend/version'
2
+
3
+ require 'yaml'
4
+ require 'deep_merge/rails_compat'
5
+
6
+ require_relative 'yaml_extend/yaml_extend_helper'
7
+
8
+ require_relative 'custom_errors/invalid_key_type_error'
9
+
10
+ #
11
+ # Extending the YAML library to allow to inherit from another YAML file(s)
12
+ #
13
+
14
+ module YAML
15
+ # default path in the yaml file where the files to inherit from are defined
16
+ DEFAULT_INHERITANCE_KEY = 'extends'
17
+ @@ext_load_key = nil
18
+ #
19
+ # Set a custom inheritance key globally once.
20
+ # So you don't need to specify it on every call of ext_load_file()
21
+ #
22
+ # @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.
23
+ def self.ext_load_key=(key)
24
+ if key.is_a?(String) || key.is_a?(Array) || key.nil?
25
+ @@ext_load_key = key
26
+ else
27
+ raise "Parameter 'key' must be of type String or Array<String> or nil"
28
+ end
29
+ end
30
+
31
+ #
32
+ # Reset the ext_load_key and use the default settings
33
+ #
34
+ def self.reset_load_key()
35
+ @@ext_load_key = nil
36
+ end
37
+ #
38
+ # Extended variant of the #load_file method by providing the
39
+ # ability to inherit from other YAML file(s)
40
+ #
41
+ # @param yaml_path [String] the path to the yaml file to be loaded
42
+ # @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']
43
+ # @param extend_existing_arrays [Boolean] extend existing arrays instead of replacing them
44
+ # @param config [Hash] a hash to be merged into the result, usually only recursivly called by the method itself
45
+ #
46
+ # @return [Hash] the resulting yaml config
47
+ #
48
+ def self.ext_load_file(yaml_path, inheritance_key=nil, extend_existing_arrays=true, config = {})
49
+ if inheritance_key.nil?
50
+ inheritance_key = @@ext_load_key || DEFAULT_INHERITANCE_KEY
51
+ end
52
+ total_config ||= {}
53
+ yaml_path = YAML.make_absolute_path yaml_path
54
+ super_config = YamlExtendHelper.encode_booleans YAML.load_file(File.open(yaml_path))
55
+ super_inheritance_files = yaml_value_by_key inheritance_key, super_config
56
+ delete_yaml_key inheritance_key, super_config # we don't merge the super inheritance keys into the base yaml
57
+ merged_config = config.clone.deeper_merge(super_config, extend_existing_arrays: extend_existing_arrays)
58
+ if super_inheritance_files && super_inheritance_files != ''
59
+ 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
60
+ super_inheritance_files.each_with_index do |super_inheritance_file, index|
61
+ super_config_path = File.dirname(yaml_path) + '/' + super_inheritance_file
62
+ total_config = YamlExtendHelper.encode_booleans YAML.ext_load_file(super_config_path, inheritance_key, extend_existing_arrays, total_config.deeper_merge(merged_config, extend_existing_arrays: extend_existing_arrays))
63
+ end
64
+ YamlExtendHelper.decode_booleans total_config
65
+ else
66
+ delete_yaml_key inheritance_key, merged_config
67
+ YamlExtendHelper.decode_booleans merged_config
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ # some logic to ensure absolute file inheritance as well as
74
+ # relative file inheritance in yaml files
75
+ def self.make_absolute_path(file_path)
76
+ private_class_method
77
+ return file_path if YAML.absolute_path?(file_path) && File.exist?(file_path)
78
+ base_path = File.dirname(caller_locations[1].path)
79
+ return base_path + '/' + file_path if File.exist? base_path + '/' + file_path # relative path from yaml file
80
+ return Dir.pwd + '/' + file_path if File.exist? Dir.pwd + '/' + file_path # relative path from project
81
+ error_message = "Can not find absolute path of '#{file_path}'"
82
+ unless YAML.absolute_path? file_path
83
+ error_message += "\nAlso tried:\n- #{base_path + '/' + file_path}\n"\
84
+ "- #{Dir.pwd + '/' + file_path}\n"
85
+ end
86
+ raise error_message
87
+ end
88
+
89
+ def self.absolute_path?(path)
90
+ private_class_method
91
+ path.start_with?('/') || # unix like
92
+ (path.length >= 3 && path[1] == ':') # ms windows
93
+ end
94
+
95
+ # Return the value of the corresponding key
96
+ # @param key [String|Array]
97
+ def self.yaml_value_by_key(key, config)
98
+ return config[key] if key.is_a? String
99
+ if valid_key_type? key
100
+ cfg_copy = config.clone
101
+ key.each do |key|
102
+ if cfg_copy.nil?
103
+ return
104
+ elsif valid_key_type? key
105
+ cfg_copy = cfg_copy[key]
106
+ end
107
+ end
108
+ cfg_copy
109
+ end
110
+ end
111
+
112
+ def self.valid_key_type?(key)
113
+ key.is_a?(Array) || key.is_a?(String) ||
114
+ raise(InvalidKeyTypeError,"Invalid key of type '#{key.class.name}'. Valid types are String and Array.")
115
+ end
116
+
117
+ def self.delete_yaml_key(key, config)
118
+ return config.delete(key) if key.is_a? String
119
+ cfg_ref = config
120
+ last_ref = nil
121
+ key.each do |key|
122
+ if valid_key_type?(key) && !cfg_ref[key].nil?
123
+ last_ref = cfg_ref
124
+ cfg_ref = cfg_ref[key] unless cfg_ref.nil?
125
+ end
126
+ end
127
+ last_ref.delete key.last unless last_ref.nil?
128
+ end
129
+
130
+ end
@@ -1,3 +1,3 @@
1
- module YamlExtend
2
- VERSION = '0.2.3'.freeze
3
- end
1
+ module YamlExtend
2
+ VERSION = '0.2.4'.freeze
3
+ end
@@ -1,68 +1,68 @@
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
-
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
68
  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: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthäus Beyrle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-04 00:00:00.000000000 Z
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.14'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.14'
41
41
  - !ruby/object:Gem::Dependency
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 2.7.7
112
+ rubygems_version: 2.7.6
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Extends YAML to support file based inheritance