summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-11-09 17:04:59 -0800
committerPete Higgins <pete@peterhiggins.org>2020-11-09 17:04:59 -0800
commit38b2e9f9f67ff6e5fcfbf50beb9dd969cb594eb3 (patch)
tree3fb5fe0cf4e63873edbc2cb67adef230b4cedbfa
parentf6f186fa5daf93f5603f76c0498b1a97c73375ea (diff)
downloadchef-cleanup-jsoncompat.tar.gz
Refactor to_json_pretty to avoid creating a hash.cleanup-jsoncompat
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/chef/json_compat.rb6
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/chef/json_compat.rb b/lib/chef/json_compat.rb
index f545c71373..b5c9072f6f 100644
--- a/lib/chef/json_compat.rb
+++ b/lib/chef/json_compat.rb
@@ -53,10 +53,8 @@ class Chef
end
def to_json_pretty(obj, opts = nil)
- opts ||= {}
- options_map = {}
- options_map[:pretty] = true
- options_map[:indent] = opts[:indent] if opts.key?(:indent)
+ options_map = { pretty: true }
+ options_map[:indent] = opts[:indent] if opts.respond_to?(:key?) && opts.key?(:indent)
to_json(obj, options_map).chomp
end