yaml_extend 0.2.0 → 0.2.1

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: e05fc2afe5d8f44419bf0c3d7a2fc801ab04e81864114b000080f6beea8337fd
4
- data.tar.gz: 46ac756ebcb6b620930eeda313673c2a5990d6e78f8fe7bf4c609576664429a3
3
+ metadata.gz: de7c8e1e42f819845db2863a976d76033d253d3583f1e7b3e5930cf9220b06f3
4
+ data.tar.gz: c8d249f5c81a4cadd8212b97a94349cceb0dbd595ab232e71617af2f7f9189ef
5
5
  SHA512:
6
- metadata.gz: 87f97749740b0954e62bf184418950f57d19612fdead49ae1cc7afb4ce6291f842bff5a887d3b4ba8fda1e2d512a61eb6a9eddf17737fe45136615138ddec27b
7
- data.tar.gz: a922bc2aa0479db54e03bda900535bad1abfb23a03360f1024aa0caea3a7a0d478c6a6861a8c8af775f9e4df63dc8b88bac93f6e755cb8fd66fd90fe941e5c45
6
+ metadata.gz: 0fa220727bf30320588fa080b4ea55455317b981ce87d9bafb9ec3262014fe243a600d9b08e5d20cb827991041c35993df52f5aea6f11441080b086551407cbb
7
+ data.tar.gz: 115fabe9445d7ad15566760e5c5d1190bf40f5fc5f8183f88b1069fe43360ff83754c861bd37db796a5bab0ef15b56cdd093084ee247bea86b761cb6ca6c1c98
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # yaml_extend
2
2
 
3
- Extends YAML to support file based inheritance,
4
- to e.g. to build a configuration hierachy.
3
+ Extends YAML to support file based inheritance.
4
+
5
+ That can be very handy to build a configuration hierachy.
5
6
 
6
7
  ## Installation
7
8
 
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
+ #
5
+ # run default task to see tasks to build and publish gem
6
+ #
4
7
  task :default do
5
8
  system 'rake --tasks'
6
9
  end
@@ -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 super_config_path, inheritance_key, extend_existing_arrays, total_config.deeper_merge(merged_config, extend_existing_arrays: extend_existing_arrays)
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
 
@@ -1,3 +1,3 @@
1
1
  module YamlExtend
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
@@ -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.0
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-03-11 00:00:00.000000000 Z
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.3
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