yaml_extend 1.3.2 → 1.3.5

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: a3521ed653597acc21b56291da2d6d9da902ec64bc2d3f1d23cd01115e55ee5b
4
- data.tar.gz: e8b491f5b356dfaee5415d07528f01bd8fbe754871826e0b7cba47c434a85c6a
3
+ metadata.gz: 03e4778ee1f4118a06fce7dcbc7bbd0a6defae359b04341f5632e1a414c2eb6e
4
+ data.tar.gz: 49ad4cfd28f6ce2d13aa66ad4c4cafe740a5f110ae1ac79f8c492fd7726c23b1
5
5
  SHA512:
6
- metadata.gz: 86dd20e904e8dcbdb5f6a5250da9b39f39aef36cabef1cfdebc8efbc1f8926ff059586d6478d24d783ca0fc8c258af8098eed765d362934fe3e68e0d9b008cb3
7
- data.tar.gz: 1a1c25d6699a920ae2d834fd2d87fda9bf4bd1e6d6736057ca80237f4aa74b9a1f8621a8ae23e9461b3e2cd857dc6ff2db46b12db604e9eca4d28bd6ba6a29ab
6
+ metadata.gz: 1b13ee198ddd926ec4569a826f12ca13229a5b574ccfede3fe4c0bf66eb8f586e6574f2d7ea91e45fc2b0e769c5002215c6b4c7333887a74efe0a37b980762e7
7
+ data.tar.gz: 20cb5a6bf6831df937dc2d68106250e7a10ead10ddfc1afb5673481afc13974234b2f7cd8144280c00f1e9b81d31992eb3716db7e65ce4cf79dfc03f44ee609b
data/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
data/README.md CHANGED
@@ -15,7 +15,7 @@ If you are just doing administration without knowing ruby, you can also just use
15
15
  * [Common information](#common-information)
16
16
  * [Installation](#installation)
17
17
  * [Usage](#usage)
18
- * [Command line](#command-line)
18
+ * [Command line](#command-line-usage)
19
19
  * [Documentation](#documentation)
20
20
  * [Contributing](#contributing)
21
21
 
@@ -63,12 +63,12 @@ gem 'yaml_extend'
63
63
 
64
64
  And then execute:
65
65
 
66
- $ bundle install
66
+ bundle install
67
67
 
68
68
  ### Command line
69
69
  If you just want to use the command line then run
70
70
 
71
- $ gem install yaml_extend
71
+ gem install yaml_extend
72
72
 
73
73
 
74
74
 
@@ -86,11 +86,13 @@ This method works like the original YAML.load_file, by extending it with file in
86
86
  Given the following both files are defined:
87
87
 
88
88
  ```yaml
89
- # start.yml
89
+ # start.erb.yml
90
90
  extends: 'super.yml'
91
91
  data:
92
92
  name: 'Mr. Superman'
93
- age: 134
93
+ age: 134
94
+ # using ERB templating with ruby code
95
+ foo: '<%= 'bar' %>'
94
96
  favorites:
95
97
  - 'Raspberrys'
96
98
  ```
@@ -108,7 +110,7 @@ data:
108
110
  When you then call `ext_load_file`
109
111
 
110
112
  ```ruby
111
- config = YAML.ext_load_file 'start.yml'
113
+ config = YAML.ext_load_file 'start.erb.yml'
112
114
  ```
113
115
 
114
116
  the returned YAML value results in
@@ -117,6 +119,7 @@ the returned YAML value results in
117
119
  data:
118
120
  name: 'Mr. Superman'
119
121
  age: 134
122
+ foo: 'bar'
120
123
  power: 2000
121
124
  favorites:
122
125
  - 'Bananas'
@@ -180,7 +183,7 @@ config = YAML.ext_load_file 'custom2.yml', ['options','extend_file']
180
183
 
181
184
 
182
185
 
183
- <a name="command-line"></a>
186
+ <a name="command-line-usage"></a>
184
187
  ## Command line
185
188
 
186
189
  `yaml_extend` is also available on the command line after installation.
@@ -198,6 +201,7 @@ Usually you might want to put the result into resulting YAML file. So just use t
198
201
  yaml_extend path/to/my/yaml_file.yml > combined_yaml.yml
199
202
  ```
200
203
 
204
+ Default options are used, custom options are not yet supported as parameters.
201
205
 
202
206
 
203
207
  <a name="documentation"></a>
@@ -220,6 +224,7 @@ YAML.ext_load_file(yaml_path, inheritance_key='extends', options = {})
220
224
  - `:extend_existing_arrays` (Boolean) Set to true to extend existing arrays, instead of overwriting them - DEFAULT: true
221
225
  - `:merge_nil_values` (Boolean) Set to true to merge nil hash values, overwriting a possibly non-nil value - DEFAULT: false
222
226
  - `:merge_debug` (Boolean) Set to true to get console output of merge process for debugging - DEFAULT: false
227
+ - `:force_erb` (Boolean) Set to true to force ERB processing on all inherited files, even if they do not end with `.erb` - DEFAULT: false
223
228
 
224
229
  See also rubydoc at [https://www.rubydoc.info/gems/yaml_extend](https://www.rubydoc.info/gems/yaml_extend)
225
230
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  #
5
5
  # run default task to see tasks to build and publish gem
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "yaml_extend"
3
+ require 'bundler/setup'
4
+ require_relative '../lib/yaml_extend'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
data/bin/yaml_extend CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'yaml_extend'
3
+ require_relative '../lib/yaml_extend'
4
4
 
5
5
  arg = ARGV[0]
6
6
 
@@ -1,3 +1,3 @@
1
1
  module YamlExtend
2
- VERSION = '1.3.2'.freeze
2
+ VERSION = '1.3.5'.freeze
3
3
  end
data/lib/yaml_extend.rb CHANGED
@@ -1,9 +1,8 @@
1
- require 'yaml_extend/version'
2
-
3
1
  require 'yaml'
4
2
  require 'erb'
5
3
  require 'deep_merge/rails_compat'
6
4
 
5
+ require_relative 'yaml_extend/version'
7
6
  require_relative 'custom_errors/invalid_key_type_error'
8
7
 
9
8
  #
@@ -68,6 +67,7 @@ module YAML
68
67
  # @option options [Boolean] :extend_existing_arrays Set to true to extend existing arrays, instead of overwriting them - DEFAULT: true
69
68
  # @option options [Boolean] :merge_nil_values Set to true to merge nil hash values, overwriting a possibly non-nil value - DEFAULT: false
70
69
  # @option options [Boolean] :merge_debug Set to true to get console output of merge process for debugging - DEFAULT: false
70
+ # @option options [Boolean] :force_erb Set to true to force ERB processing of the yaml file, even if it does not end with '.erb' or include '.erb.' in the file name - DEFAULT: false
71
71
  #
72
72
  # @param [Boolean] options Fallback for backward compatiblity: extend existing arrays instead of replacing them (deep_merge)
73
73
  # @return [Hash] the resulting yaml config
@@ -100,6 +100,7 @@ module YAML
100
100
  extend_existing_arrays: true,
101
101
  merge_nil_values: false,
102
102
  merge_debug: false,
103
+ force_erb: false,
103
104
  }
104
105
  options = default_options.merge options
105
106
  private_class_method
@@ -111,7 +112,7 @@ module YAML
111
112
  yaml_path = YAML.make_absolute_path yaml_path
112
113
 
113
114
  super_config =
114
- if yaml_path.match(/(\.erb\.|\.erb$)/)
115
+ if options[:force_erb] || yaml_path.match(/(\.erb\.|\.erb$)/)
115
116
  if YAML.respond_to? :unsafe_load # backward compatibility for Ruby 3.1 / Psych 4
116
117
  YAML.unsafe_load(ERB.new(File.read(yaml_path)).result)
117
118
  else
@@ -181,6 +182,7 @@ module YAML
181
182
  # Return the value of the corresponding key
182
183
  # @param key [String|Array]
183
184
  def self.yaml_value_by_key(key, config)
185
+ return nil if config.nil? # config is nil, if the yaml file is empty
184
186
  return config[key] if key.is_a? String
185
187
  if valid_key_type? key
186
188
  cfg_copy = config.clone
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.3.2
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthäus Beyrle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-16 00:00:00.000000000 Z
11
+ date: 2025-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -74,6 +74,7 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - ".gitattributes"
77
78
  - ".gitignore"
78
79
  - ".rspec"
79
80
  - ".travis.yml"