extended_yaml 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75375be6f35d137f2c0cc92fcd0a69b8c706ab0f4152566d0b6dc037d0b66204
4
- data.tar.gz: 6ea26f239f8a148d5e07c0e20f6e30e734834ffe37953be1e79041b47fd21257
3
+ metadata.gz: b0a13910aac060ea32e2ff09ffbcc33ef5e772e69699c6d0073715ebcb5f1f78
4
+ data.tar.gz: 6cf463213f5d101227b0c837dd7317b24619d20b2e9fd22188d96c84b0167c75
5
5
  SHA512:
6
- metadata.gz: 8df1afcc6db22d7a5ce02f67c71839d2e62648af49f0df3532fcec88965506e7a758df286d507720097de766f38f378b060ba1eba350b59ef01729dcbb21b91b
7
- data.tar.gz: 91592326390e18c981cf25cd668c63a9727c8b3b9ce067ef9006e112d845fcf6c034e324baf3dc5c1a42070c628c6cf9b89d1ce639a244e78735d169ba2becdd
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. If you need to use a key that is named differently, provide it using the
68
- `key` keyword argument:
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
@@ -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 = [extra_files] unless extra_files.is_a? Array
47
+ extra_files = expand_file_list extra_files
48
48
 
49
- extra_files.each do |extra_file|
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
@@ -1,3 +1,3 @@
1
1
  class ExtendedYAML
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.0
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-25 00:00:00.000000000 Z
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