diff options
author | Pierre Ynard <p.ynard@criteo.com> | 2014-01-10 10:32:06 +0100 |
---|---|---|
committer | Pierre Ynard <p.ynard@criteo.com> | 2014-01-10 10:32:06 +0100 |
commit | 68f99fc6c65cba739dad20f95df1c558ede66946 (patch) | |
tree | c33ac10372f0b7ce4816ace17b50c0b39a3c29ff /lib/chef/node | |
parent | cbbf8f8f2169945451da6fff76c75bd79da307e1 (diff) | |
download | chef-68f99fc6c65cba739dad20f95df1c558ede66946.tar.gz |
[CHEF-4799] Handle non-dupable elements when duping attribute arrays
Diffstat (limited to 'lib/chef/node')
-rw-r--r-- | lib/chef/node/attribute_collections.rb | 9 | ||||
-rw-r--r-- | lib/chef/node/immutable_collections.rb | 9 |
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb index d5d496fd60..f09b02b106 100644 --- a/lib/chef/node/attribute_collections.rb +++ b/lib/chef/node/attribute_collections.rb @@ -76,8 +76,15 @@ class Chef super(data) end + # For elements like Fixnums, true, nil... + def safe_dup(e) + e.dup + rescue TypeError + e + end + def dup - Array.new(map {|e| e.dup}) + Array.new(map {|e| safe_dup(e)}) end end diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb index f5b3a5121d..63ac2b4c6b 100644 --- a/lib/chef/node/immutable_collections.rb +++ b/lib/chef/node/immutable_collections.rb @@ -85,8 +85,15 @@ class Chef METHOD_DEFN end + # For elements like Fixnums, true, nil... + def safe_dup(e) + e.dup + rescue TypeError + e + end + def dup - Array.new(map {|e| e.dup }) + Array.new(map {|e| safe_dup(e)}) end end |