yaml_extend 1.1.1 → 1.2.0

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: 260457e93f7baaedfbc284c732e7b3efbd34ba57c4d4e7d8bfeae0112bb464c4
4
- data.tar.gz: 39ee43948691830d4c3e241a7bad1aaae0586fa36eb91f0b120d72800657fe30
3
+ metadata.gz: 053aef54e93b410f7b2eb373834abff17b4f1a2627d292f2eacb479fb78d4d9b
4
+ data.tar.gz: 70dd53ab46254a6dfed23530c74e3668d14a81844792ac980d4c03b0fb141d24
5
5
  SHA512:
6
- metadata.gz: 5ee160e95852303ad939d92666c480e89b292da689d4bb054256374919be77a66ca4baf28228044d6630b4b840db3cd46b66a53e2647a1569950451f0e8540bb
7
- data.tar.gz: d9ed54ef19a39c9c6bc2838b162e2eeb0dbb162833780d38566403d706bdf24cf985e0d9b8df49a4ac84147323c51e7aadde7ae6d3d5ed304ee02b80ad145317
6
+ metadata.gz: 390f032971732ece98f75c58bf471da9ce8085918cbedcf40fd840087a30e45da8a0db7df2fc06030d965ac9b0dae170f2745cdcacb09cf30b2acbcfe9d4118a
7
+ data.tar.gz: de9bfd1e7e9e2bf45f6783f387284720fdc54db997a6ba9f0eacf4b03a57f6fd2deb9c3596b868e81695da39873c277beefaee3d99ad7b31ffee103d4e208cfd
@@ -1,3 +1,3 @@
1
1
  module YamlExtend
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
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
@@ -69,7 +69,7 @@ module YAML
69
69
  # @option options [Boolean] :merge_debug Set to true to get console output of merge process for debugging - DEFAULT: false
70
70
  #
71
71
  # @param [Boolean] options Fallback for backward compatiblity: extend existing arrays instead of replacing them (deep_merge)
72
- # @return [Hash] the resulting yaml config
72
+ # @return [Hash] the resulting yaml config
73
73
  #
74
74
  def self.ext_load_file(yaml_path, inheritance_key = nil, options = {})
75
75
  YAML.ext_load_file_recursive(yaml_path, inheritance_key, options, {})
@@ -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 config [Hash] a hash to be merged into the result, usually only recursivly called by the method itself
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}
@@ -108,9 +111,9 @@ module YAML
108
111
 
109
112
  super_config =
110
113
  if yaml_path.match(/(\.erb\.|\.erb$)/)
111
- YAML.load(ERB.new(File.read(yaml_path)).result)
114
+ YAML.unsafe_load(ERB.new(File.read(yaml_path)).result)
112
115
  else
113
- YAML.load_file(File.open(yaml_path))
116
+ YAML.unsafe_load_file(File.open(yaml_path))
114
117
  end
115
118
 
116
119
  super_inheritance_files = yaml_value_by_key inheritance_key, super_config
@@ -135,16 +138,20 @@ module YAML
135
138
  total_config.deeper_merge!(super_config, deep_merge_options)
136
139
  end
137
140
 
138
- # some logic to ensure absolute file inheritance as well as
139
- # relative file inheritance in yaml files
141
+ # some logic to ensure absolute file inheritance as well as
142
+ # relative file inheritance in yaml files
140
143
  def self.make_absolute_path(file_path)
141
144
  private_class_method
142
145
  return file_path if YAML.absolute_path?(file_path) && File.exist?(file_path)
143
146
  # caller_locations returns the current execution stack
144
147
  # [0] is the call from ext_load_file_recursive,
145
148
  # [1] is inside ext_load_file,
146
- # [2] is the exteranl caller of YAML.ext_load_file
147
- base_path = File.dirname(caller_locations[2].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
148
155
  return base_path + '/' + file_path if File.exist? base_path + '/' + file_path # relative path from yaml file
149
156
  return Dir.pwd + '/' + file_path if File.exist? Dir.pwd + '/' + file_path # relative path from project
150
157
  error_message = "Can not find absolute path of '#{file_path}'"
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.1.1
4
+ version: 1.2.0
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: 2021-01-26 00:00:00.000000000 Z
11
+ date: 2022-07-19 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.0.8
110
+ rubygems_version: 3.3.7
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Extends YAML to support file based inheritance