extended_yaml 0.1.0 → 0.1.1
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 -3
- data/lib/extended_yaml.rb +30 -5
- data/lib/extended_yaml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0a13910aac060ea32e2ff09ffbcc33ef5e772e69699c6d0073715ebcb5f1f78
|
4
|
+
data.tar.gz: 6cf463213f5d101227b0c837dd7317b24619d20b2e9fd22188d96c84b0167c75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 290431c92d5fd8fd2daa5995fcbfd41a7f78c4a43a7585dd372c9e0bd00464da65503af27929fcdd0b4b28ee3eea2d70579a77084e06511109f9567bcddebf1f
|
7
|
+
data.tar.gz: 4d175288fabf5f65755f1df99a3f758cd3ff283d283d7be5bf9ac289dc490191a8996bcfb5d258efa6c62d52af495f563366e74d2b5c3895dcff344d41d397f1
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@ Extended YAML
|
|
2
2
|
==================================================
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/extended_yaml.svg)](https://badge.fury.io/rb/extended_yaml)
|
5
|
+
[![Build Status](https://travis-ci.com/DannyBen/extended_yaml.svg?branch=master)](https://travis-ci.com/DannyBen/extended_yaml)
|
6
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/0d162ff84c50abe7c83a/maintainability)](https://codeclimate.com/github/DannyBen/extended_yaml/maintainability)
|
5
7
|
|
6
8
|
---
|
7
9
|
|
@@ -64,10 +66,12 @@ Notes
|
|
64
66
|
4. ERB tags will be evaluated in all YAML files.
|
65
67
|
5. The `extends` option can use either a single file string, or an array.
|
66
68
|
Extensions are optional.
|
67
|
-
6.
|
68
|
-
|
69
|
+
6. Using `*` anywhere in the `extends` path will load multiple files with one
|
70
|
+
call.
|
71
|
+
7. If you need to use a key that is named differently than `extends`, provide
|
72
|
+
it using the `key` keyword argument:
|
69
73
|
```ruby
|
70
|
-
ExtendedYAML.load 'examples/simple.yml, key: 'include'
|
74
|
+
ExtendedYAML.load 'examples/simple.yml', key: 'include'
|
71
75
|
```
|
72
76
|
|
73
77
|
See the [examples/master.yml](examples/master.yml) file for additional
|
data/lib/extended_yaml.rb
CHANGED
@@ -38,20 +38,45 @@ private
|
|
38
38
|
@base_dir ||= File.dirname file
|
39
39
|
end
|
40
40
|
|
41
|
-
# @param [Hash] data structure, possibly with 'extends' array
|
41
|
+
# @param [Hash] data the data structure, possibly with 'extends' array
|
42
42
|
# @return [Hash] the merged data
|
43
43
|
def resolve_extends(data)
|
44
44
|
extra_files = data.delete key
|
45
45
|
return data unless extra_files
|
46
46
|
|
47
|
-
extra_files =
|
47
|
+
extra_files = expand_file_list extra_files
|
48
48
|
|
49
|
-
extra_files.each do |
|
50
|
-
extra_file = extra_file + extension unless extra_file.end_with? extension
|
51
|
-
path = File.expand_path extra_file, base_dir
|
49
|
+
extra_files.each do |path|
|
52
50
|
data.deep_merge! self.class.new(path).result
|
53
51
|
end
|
54
52
|
|
55
53
|
data
|
56
54
|
end
|
55
|
+
|
56
|
+
# Receives a string or an array of strings, each representing an acceptable
|
57
|
+
# path definition. Each definition may be with or without a file etxension,
|
58
|
+
# and may be a glob pattern. The resulting array will be a normalized list
|
59
|
+
# of full paths.
|
60
|
+
#
|
61
|
+
# @param [Array, String] files one or more path definitions
|
62
|
+
# @return [Array] a normalized list of absolute paths
|
63
|
+
def expand_file_list(files)
|
64
|
+
list = []
|
65
|
+
files = [files] unless files.is_a? Array
|
66
|
+
|
67
|
+
files.each do |path|
|
68
|
+
list += expand_path path
|
69
|
+
end
|
70
|
+
|
71
|
+
list
|
72
|
+
end
|
73
|
+
|
74
|
+
# @param [String] path the path to the YAML file, with or without extension.
|
75
|
+
# May include a glob pattern wildcard.
|
76
|
+
# @return [Array] one or more absolute paths.
|
77
|
+
def expand_path(path)
|
78
|
+
path += extension unless path.end_with? extension
|
79
|
+
path = File.expand_path path, base_dir
|
80
|
+
path.include?('*') ? Dir[path] : [path]
|
81
|
+
end
|
57
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extended_yaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Load YAML files that deep merge other YAML files
|
14
14
|
email: db@dannyben.com
|