-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add patch to make correct merging of booleans possible in deep_merge
The deep_merge gem lacks on a issue, reported here: danielsdeleo/deep_merge#23 danielsdeleo/deep_merge#28 As yaml_extend uses this gem to merge, here is a workaround to solve this issue. It will be full forward compatible, if the original deep_merge solves its issue, due we don't patch deep_merge directly in any way.
- Loading branch information
entwanderer
committed
May 27, 2018
1 parent
9c68e6d
commit 494cd1f
Showing
5 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
# | ||
# This class includes a workaround patch, providing a solution of the unaccepted pull request | ||
# 'false is not overriden by true if preserve_unmergeables' | ||
# https://github.com/danielsdeleo/deep_merge/pull/28 | ||
# | ||
# It ensures, that booleans can be merged correctly, by en- and decoding them to strings, before and after merging | ||
# see #encode_boolens and #decode_booleans | ||
# | ||
|
||
class YamlExtendHelper | ||
|
||
TRUE_CLASS_ENCODED = '#={TrueClass}=#' | ||
FALSE_CLASS_ENCODED = '#={FalseClass}=#' | ||
|
||
def self.encode_booleans(hash) | ||
hash.each_with_object({}) do |(k,v),g| | ||
g[k] = if v.is_a? Hash | ||
YamlExtendHelper.encode_booleans(v) | ||
elsif v.is_a? Array | ||
v.each_with_index do |av, ai| | ||
v[ai] = if av.is_a? Hash | ||
YamlExtendHelper.encode_booleans(av) | ||
elsif av.is_a? TrueClass | ||
TRUE_CLASS_ENCODED | ||
elsif av.is_a? FalseClass | ||
FALSE_CLASS_ENCODED | ||
else | ||
av | ||
end | ||
end | ||
elsif v.is_a? TrueClass | ||
TRUE_CLASS_ENCODED | ||
elsif v.is_a? FalseClass | ||
FALSE_CLASS_ENCODED | ||
else | ||
v | ||
end | ||
end | ||
end | ||
|
||
def self.decode_booleans(hash) | ||
hash.each_with_object({}) do |(k,v),g| | ||
g[k] = if v.is_a? Hash | ||
YamlExtendHelper.decode_booleans(v) | ||
elsif v.is_a? Array | ||
v.each_with_index do |av, ai| | ||
v[ai] = if av.is_a? Hash | ||
YamlExtendHelper.decode_booleans(av) | ||
elsif av === TRUE_CLASS_ENCODED | ||
true | ||
elsif av === FALSE_CLASS_ENCODED | ||
false | ||
else | ||
av | ||
end | ||
end | ||
elsif v === TRUE_CLASS_ENCODED | ||
true | ||
elsif v === FALSE_CLASS_ENCODED | ||
false | ||
else | ||
v | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
alpha: true | ||
beta: false | ||
gamma: true | ||
data: | ||
delta: false | ||
kappa: true | ||
theta: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extends: 'base.yml' | ||
alpha: false | ||
beta: true | ||
data: | ||
delta: true | ||
kappa: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters