yaml_extend 0.2.0 → 0.2.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 +4 -4
- data/README.md +3 -2
- data/Rakefile +3 -0
- data/lib/yaml_extend.rb +6 -4
- data/lib/yaml_extend/version.rb +1 -1
- data/lib/yaml_extend/yaml_extend_helper.rb +68 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de7c8e1e42f819845db2863a976d76033d253d3583f1e7b3e5930cf9220b06f3
|
4
|
+
data.tar.gz: c8d249f5c81a4cadd8212b97a94349cceb0dbd595ab232e71617af2f7f9189ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fa220727bf30320588fa080b4ea55455317b981ce87d9bafb9ec3262014fe243a600d9b08e5d20cb827991041c35993df52f5aea6f11441080b086551407cbb
|
7
|
+
data.tar.gz: 115fabe9445d7ad15566760e5c5d1190bf40f5fc5f8183f88b1069fe43360ff83754c861bd37db796a5bab0ef15b56cdd093084ee247bea86b761cb6ca6c1c98
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/yaml_extend.rb
CHANGED
@@ -3,6 +3,8 @@ require 'yaml_extend/version'
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'deep_merge/rails_compat'
|
5
5
|
|
6
|
+
require_relative 'yaml_extend/yaml_extend_helper'
|
7
|
+
|
6
8
|
require_relative 'custom_errors/invalid_key_type_error'
|
7
9
|
|
8
10
|
#
|
@@ -49,7 +51,7 @@ module YAML
|
|
49
51
|
end
|
50
52
|
total_config ||= {}
|
51
53
|
yaml_path = YAML.make_absolute_path yaml_path
|
52
|
-
super_config = YAML.load_file(File.open(yaml_path))
|
54
|
+
super_config = YamlExtendHelper.encode_booleans YAML.load_file(File.open(yaml_path))
|
53
55
|
super_inheritance_files = yaml_value_by_key inheritance_key, super_config
|
54
56
|
delete_yaml_key inheritance_key, super_config # we don't merge the super inheritance keys into the base yaml
|
55
57
|
merged_config = config.clone.deeper_merge(super_config, extend_existing_arrays: extend_existing_arrays)
|
@@ -57,12 +59,12 @@ module YAML
|
|
57
59
|
super_inheritance_files = [super_inheritance_files] unless super_inheritance_files.is_a? Array # we support strings as well as arrays of type string to extend from
|
58
60
|
super_inheritance_files.each_with_index do |super_inheritance_file, index|
|
59
61
|
super_config_path = File.dirname(yaml_path) + '/' + super_inheritance_file
|
60
|
-
total_config = YAML.ext_load_file
|
62
|
+
total_config = YamlExtendHelper.encode_booleans YAML.ext_load_file(super_config_path, inheritance_key, extend_existing_arrays, total_config.deeper_merge(merged_config, extend_existing_arrays: extend_existing_arrays))
|
61
63
|
end
|
62
|
-
total_config
|
64
|
+
YamlExtendHelper.decode_booleans total_config
|
63
65
|
else
|
64
66
|
delete_yaml_key inheritance_key, merged_config
|
65
|
-
merged_config
|
67
|
+
YamlExtendHelper.decode_booleans merged_config
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
data/lib/yaml_extend/version.rb
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# This class includes a workaround patch, providing a solution of the unaccepted pull request
|
4
|
+
# 'false is not overriden by true if preserve_unmergeables'
|
5
|
+
# https://github.com/danielsdeleo/deep_merge/pull/28
|
6
|
+
#
|
7
|
+
# It ensures, that booleans can be merged correctly, by en- and decoding them to strings, before and after merging
|
8
|
+
# see #encode_boolens and #decode_booleans
|
9
|
+
#
|
10
|
+
|
11
|
+
class YamlExtendHelper
|
12
|
+
|
13
|
+
TRUE_CLASS_ENCODED = '#={TrueClass}=#'
|
14
|
+
FALSE_CLASS_ENCODED = '#={FalseClass}=#'
|
15
|
+
|
16
|
+
def self.encode_booleans(hash)
|
17
|
+
hash.each_with_object({}) do |(k,v),g|
|
18
|
+
g[k] = if v.is_a? Hash
|
19
|
+
YamlExtendHelper.encode_booleans(v)
|
20
|
+
elsif v.is_a? Array
|
21
|
+
v.each_with_index do |av, ai|
|
22
|
+
v[ai] = if av.is_a? Hash
|
23
|
+
YamlExtendHelper.encode_booleans(av)
|
24
|
+
elsif av.is_a? TrueClass
|
25
|
+
TRUE_CLASS_ENCODED
|
26
|
+
elsif av.is_a? FalseClass
|
27
|
+
FALSE_CLASS_ENCODED
|
28
|
+
else
|
29
|
+
av
|
30
|
+
end
|
31
|
+
end
|
32
|
+
elsif v.is_a? TrueClass
|
33
|
+
TRUE_CLASS_ENCODED
|
34
|
+
elsif v.is_a? FalseClass
|
35
|
+
FALSE_CLASS_ENCODED
|
36
|
+
else
|
37
|
+
v
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.decode_booleans(hash)
|
43
|
+
hash.each_with_object({}) do |(k,v),g|
|
44
|
+
g[k] = if v.is_a? Hash
|
45
|
+
YamlExtendHelper.decode_booleans(v)
|
46
|
+
elsif v.is_a? Array
|
47
|
+
v.each_with_index do |av, ai|
|
48
|
+
v[ai] = if av.is_a? Hash
|
49
|
+
YamlExtendHelper.decode_booleans(av)
|
50
|
+
elsif av === TRUE_CLASS_ENCODED
|
51
|
+
true
|
52
|
+
elsif av === FALSE_CLASS_ENCODED
|
53
|
+
false
|
54
|
+
else
|
55
|
+
av
|
56
|
+
end
|
57
|
+
end
|
58
|
+
elsif v === TRUE_CLASS_ENCODED
|
59
|
+
true
|
60
|
+
elsif v === FALSE_CLASS_ENCODED
|
61
|
+
false
|
62
|
+
else
|
63
|
+
v
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
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: 0.2.
|
4
|
+
version: 0.2.1
|
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: 2018-
|
11
|
+
date: 2018-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/custom_errors/invalid_key_type_error.rb
|
87
87
|
- lib/yaml_extend.rb
|
88
88
|
- lib/yaml_extend/version.rb
|
89
|
+
- lib/yaml_extend/yaml_extend_helper.rb
|
89
90
|
- yaml_extend.gemspec
|
90
91
|
homepage: https://github.com/entwanderer/yaml_extend
|
91
92
|
licenses:
|
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
version: '0'
|
109
110
|
requirements: []
|
110
111
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.7.
|
112
|
+
rubygems_version: 2.7.7
|
112
113
|
signing_key:
|
113
114
|
specification_version: 4
|
114
115
|
summary: Extends YAML to support file based inheritance
|