diff options
author | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-09-27 10:16:12 +0530 |
---|---|---|
committer | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-09-27 10:16:12 +0530 |
commit | 1a049aa3a42d8ce785afdbe8467d249991baf2c4 (patch) | |
tree | 4c60c42a2408b7c63bf7b1a76e6496bf30bed31d /lib | |
parent | 49ff9da07c01255c36650ca55874ac067c0e68bd (diff) | |
download | chef-1a049aa3a42d8ce785afdbe8467d249991baf2c4.tar.gz |
Override the #to_yaml method for ImmutableMash & ImmutableArray
- Psych module to_yaml not working as expected for ImmutableMash & ImmutableArray.
- So parse first to Hash/Array then convert it to YAML formatted string.
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/node/immutable_collections.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb index b4a7a39ba0..96e589fdaa 100644 --- a/lib/chef/node/immutable_collections.rb +++ b/lib/chef/node/immutable_collections.rb @@ -96,6 +96,12 @@ class Chef alias_method :to_array, :to_a + # As Psych module, not respecting Immutable ImmutableArray object + # So first convert it to Hash/Array then parse it to `.to_yaml` + def to_yaml(*opts) + to_a.to_yaml(*opts) + end + private # needed for __path__ @@ -168,6 +174,12 @@ class Chef alias_method :to_hash, :to_h + # As Psych module, not respecting ImmutableMash object + # So first convert it to Hash/Array then parse it to `.to_yaml` + def to_yaml(*opts) + to_h.to_yaml(*opts) + end + # For elements like Fixnums, true, nil... def safe_dup(e) e.dup |