From dbb339175b445bcd4dfd6c54bababf9dd7908993 Mon Sep 17 00:00:00 2001 From: Noah Kantrowitz Date: Tue, 4 Apr 2017 00:19:41 -0700 Subject: =?UTF-8?q?Cope=20with=20the=20common=20case=20of=20passing=20node?= =?UTF-8?q?[=E2=80=9Cwhatever=E2=80=9D]=20as=20template=20variables.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Noah Kantrowitz --- lib/chef/provider/template/content.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/chef/provider') diff --git a/lib/chef/provider/template/content.rb b/lib/chef/provider/template/content.rb index 76a3e6d169..b40794564a 100644 --- a/lib/chef/provider/template/content.rb +++ b/lib/chef/provider/template/content.rb @@ -40,8 +40,12 @@ class Chef visitor = lambda do |obj| case obj when Hash + # If this is an Attribute object, we need to change class otherwise + # we get the immutable behavior. This could probably be fixed by + # using Hash#transform_values once we only support Ruby 2.4. + obj_class = obj.is_a?(Chef::Node::ImmutableMash) ? Mash : obj.class # Avoid mutating hashes in the resource in case we're changing anything. - obj.each_with_object(obj.class.new) do |(key, value), memo| + obj.each_with_object(obj_class.new) do |(key, value), memo| memo[key] = visitor.call(value) end when Array -- cgit v1.2.1