Class: YamlExtendHelper
- Inherits:
-
Object
- Object
- YamlExtendHelper
- Defined in:
- lib/yaml_extend/yaml_extend_helper.rb
Overview
This class includes a workaround patch, providing a solution of the unaccepted pull request ‘false is not overriden by true if preserve_unmergeables’ 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
Constant Summary collapse
- TRUE_CLASS_ENCODED =
'#={TrueClass}=#'- FALSE_CLASS_ENCODED =
'#={FalseClass}=#'
Class Method Summary collapse
Class Method Details
.decode_booleans(hash) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/yaml_extend/yaml_extend_helper.rb', line 42 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 |
.encode_booleans(hash) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/yaml_extend/yaml_extend_helper.rb', line 16 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 |