diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-11-15 16:20:55 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-11-15 16:20:55 -0800 |
commit | d36473f78465d476d2dcaff3789a25a787827d58 (patch) | |
tree | c2695935d3a38cffa92f56e974113d283550d67c | |
parent | 9689452421b9cbbb26a5112c29be15c74cbf6014 (diff) | |
download | chef-d36473f78465d476d2dcaff3789a25a787827d58.tar.gz |
simplify some overly complicated powershell codelcg/unified-integer
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/mixin/powershell_type_coercions.rb | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/chef/mixin/powershell_type_coercions.rb b/lib/chef/mixin/powershell_type_coercions.rb index 4ec555ded6..792ec18842 100644 --- a/lib/chef/mixin/powershell_type_coercions.rb +++ b/lib/chef/mixin/powershell_type_coercions.rb @@ -21,31 +21,31 @@ class Chef module Mixin module PowershellTypeCoercions - def type_coercions - @type_coercions ||= { - Integer => { :type => lambda { |x| x.to_s } }, - Float => { :type => lambda { |x| x.to_s } }, - FalseClass => { :type => lambda { |x| "$false" } }, - TrueClass => { :type => lambda { |x| "$true" } }, - Hash => { :type => Proc.new { |x| translate_hash(x) } }, - Array => { :type => Proc.new { |x| translate_array(x) } }, - Chef::Node::ImmutableMash => { :type => Proc.new { |x| translate_hash(x) } }, - Chef::Node::ImmutableArray => { :type => Proc.new { |x| translate_array(x) } }, - } + def type_coercion(value) + case value + when Integer, Float + value.to_s + when FalseClass + "$false" + when TrueClass + "$true" + when Hash, Chef::Node::ImmutableMash + translate_hash(value) + when Array, Chef::Node::ImmutableArray + translate_array(value) + end end - def translate_type(value) - translation = type_coercions[value.class] - - if translation - translation[:type].call(value) - elsif value.respond_to? :to_psobject + def psobject_conversion(value) + if value.respond_to?(:to_psobject) "(#{value.to_psobject})" - else - safe_string(value.to_s) end end + def translate_type(value) + type_coercion(value) || psobject_conversion(value) || safe_string(value.to_s) + end + private def translate_hash(x) |