summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-03-13 19:54:38 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-03-13 19:54:38 -0700
commitd28d5c65d0074e6a5e3786555b5f31893447b157 (patch)
treec8a5b9986bedee4c5b032f3f4ef35850cdcef9b5 /lib
parent8cd2899fa40e21089d832b0a786b8fc4d335d738 (diff)
downloadchef-lcg/deep-dup-attrs.tar.gz
additional fix deep-duping as welllcg/deep-dup-attrs
similarly to fixing to_hash. kind of feels like we should return a VividMash instead of a Mash here, to get a writable thing that behaves like an attribute... Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/node/immutable_collections.rb33
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb
index 08bd9c9c77..13a8aefe97 100644
--- a/lib/chef/node/immutable_collections.rb
+++ b/lib/chef/node/immutable_collections.rb
@@ -70,19 +70,16 @@ class Chef
end
def to_a
- a = Array.new
- each do |v|
- a <<
- case v
- when ImmutableArray
- v.to_a
- when ImmutableMash
- v.to_h
- else
- safe_dup(v)
- end
- end
- a
+ Array.new(map do |v|
+ case v
+ when ImmutableArray
+ v.to_a
+ when ImmutableMash
+ v.to_h
+ else
+ safe_dup(v)
+ end
+ end)
end
alias_method :to_array, :to_a
@@ -129,6 +126,10 @@ class Chef
# Mash uses #convert_value to mashify values on input.
# Since we're handling this ourselves, override it to be a no-op
+ #
+ # FIXME? this seems wrong to do and i think is responsible for
+ # #dup needing to be more complicated than Mash.new(self)?
+ #
def convert_value(value)
value
end
@@ -139,7 +140,11 @@ class Chef
# Of course, 'default' has a specific meaning in Chef-land
def dup
- Mash.new(self)
+ h = Mash.new
+ each_pair do |k, v|
+ h[k] = safe_dup(v)
+ end
+ h
end
def to_h