summaryrefslogtreecommitdiff
path: root/lib/chef/node
diff options
context:
space:
mode:
authorbrianbianco <brian.bianco@gmail.com>2013-03-05 10:38:47 -0500
committerBryan McLellan <btm@getchef.com>2014-03-28 16:38:44 -0700
commit4cad176f2912475c7e36f3e86eea42fea4d51a35 (patch)
tree1f70ebf580e6f9a06787e4338422055139903c76 /lib/chef/node
parent433d8588d100dd7e99cb7a9eba3d869fe8a4d25b (diff)
downloadchef-4cad176f2912475c7e36f3e86eea42fea4d51a35.tar.gz
[CHEF-3953] ImmutableMash and ImmutableArray should implement to_hash and to_a respectively
- ImmutableMash now implements a to_hash method. This recurses through the ImmutableMash and returns a fully mutable Hash - ImmutableArray now implements a to_a method. This recurses through the ImmutableArray and returns a fully mutable Array - Unit tests added for both of the above methods
Diffstat (limited to 'lib/chef/node')
-rw-r--r--lib/chef/node/immutable_collections.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb
index 63ac2b4c6b..6dc40ce949 100644
--- a/lib/chef/node/immutable_collections.rb
+++ b/lib/chef/node/immutable_collections.rb
@@ -96,6 +96,18 @@ class Chef
Array.new(map {|e| safe_dup(e)})
end
+ def to_a
+ a = Array.new
+ each do |v|
+ if v.kind_of?(Chef::Node::ImmutableArray)
+ a.push v.to_a
+ else
+ a.push v
+ end
+ end
+ a
+ end
+
end
# == ImmutableMash
@@ -187,6 +199,18 @@ class Chef
Mash.new(self)
end
+ def to_hash
+ h = Hash.new
+ each_pair do |k,v|
+ if v.kind_of?(Chef::Node::ImmutableMash)
+ h[k] = v.to_hash
+ else
+ h[k] = v
+ end
+ end
+ h
+ end
+
end
end