yaml_extend 1.0.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/lib/yaml_extend.rb +19 -5
- data/lib/yaml_extend/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 201e99bcd2bf59ad4ce96e1d3e8f33a1146c4bef133152cff94a91a8c61d0448
|
4
|
+
data.tar.gz: 1c80344acb3e7f823259fdfb8c329927ffb4ef7a1166a48f0de27cfe8ab7a6cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 492f4243fd80eb5ae57b0824d774a588af5722992171a0e3e732cab7b28c0b771dade6221b50e98050a14153477be0b8304894575ac2871c6b8adae77700e519
|
7
|
+
data.tar.gz: b6c37c0eec5829fa359d9d0abc389f439c2382dc87914b76268a72ecfff4cd8821feefeb8301c35af96bcdc1047de226d06944ebed1ba617aae885e3ad3f6001
|
data/README.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
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)
|
2
5
|
|
3
|
-
Extends YAML to support file based inheritance.
|
6
|
+
> Extends YAML to support file based inheritance.
|
4
7
|
|
5
|
-
That can be very handy to build a configuration
|
8
|
+
That can be very handy to build a configuration hierarchy.
|
9
|
+
|
10
|
+
Basic support for ERB (embedded ruby) is included and automatically applied when config files are named `*.erb` or `*.erb.*`.
|
6
11
|
|
7
12
|
## Installation
|
8
13
|
|
data/lib/yaml_extend.rb
CHANGED
@@ -50,7 +50,7 @@ module YAML
|
|
50
50
|
# Extended variant of the YAML.load_file method by providing the
|
51
51
|
# ability to inherit from other YAML file(s)
|
52
52
|
#
|
53
|
-
# @param [String] yaml_path the path to the yaml file to be loaded
|
53
|
+
# @param [String|Pathname] yaml_path the path to the yaml file to be loaded
|
54
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
55
|
# @param [Hash] options to pass, including deep_merge options as well as
|
56
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
|
@@ -77,10 +77,13 @@ module YAML
|
|
77
77
|
|
78
78
|
private
|
79
79
|
|
80
|
+
# Same doc as ext_load_file, but extended by additional parameter 'config'
|
80
81
|
#
|
81
|
-
# @param
|
82
|
+
# @param [Hash] config a hash to be merged into the result, usually only recursively called by the method itself
|
82
83
|
#
|
83
84
|
def self.ext_load_file_recursive(yaml_path, inheritance_key, options = {}, config)
|
85
|
+
# Allow also class Pathname instead of class String
|
86
|
+
yaml_path = yaml_path.to_s
|
84
87
|
# backward compatibility to 1.0.1
|
85
88
|
if options == true || options == false
|
86
89
|
options = {extend_existing_arrays: options}
|
@@ -105,7 +108,14 @@ module YAML
|
|
105
108
|
total_config = config.clone
|
106
109
|
|
107
110
|
yaml_path = YAML.make_absolute_path yaml_path
|
108
|
-
|
111
|
+
|
112
|
+
super_config =
|
113
|
+
if yaml_path.match(/(\.erb\.|\.erb$)/)
|
114
|
+
YAML.load(ERB.new(File.read(yaml_path)).result)
|
115
|
+
else
|
116
|
+
YAML.load_file(File.open(yaml_path))
|
117
|
+
end
|
118
|
+
|
109
119
|
super_inheritance_files = yaml_value_by_key inheritance_key, super_config
|
110
120
|
unless options[:preserve_inheritance_key]
|
111
121
|
delete_yaml_key inheritance_key, super_config # we don't merge the super inheritance keys into the base yaml
|
@@ -136,8 +146,12 @@ module YAML
|
|
136
146
|
# caller_locations returns the current execution stack
|
137
147
|
# [0] is the call from ext_load_file_recursive,
|
138
148
|
# [1] is inside ext_load_file,
|
139
|
-
# [2] is the
|
140
|
-
base_path =
|
149
|
+
# [2] is the external caller of YAML.ext_load_file
|
150
|
+
base_path = if defined?(caller_locations)
|
151
|
+
File.dirname(caller_locations[2].path)
|
152
|
+
else # Fallback for ruby < 2.1.10
|
153
|
+
File.dirname(caller[2])
|
154
|
+
end
|
141
155
|
return base_path + '/' + file_path if File.exist? base_path + '/' + file_path # relative path from yaml file
|
142
156
|
return Dir.pwd + '/' + file_path if File.exist? Dir.pwd + '/' + file_path # relative path from project
|
143
157
|
error_message = "Can not find absolute path of '#{file_path}'"
|
data/lib/yaml_extend/version.rb
CHANGED
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.1.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:
|
11
|
+
date: 2021-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
110
|
+
rubygems_version: 3.1.4
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Extends YAML to support file based inheritance
|