diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-11-16 12:25:38 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-16 12:25:38 -0800 |
commit | df70293a5d79a9f51d02453ea055600fc77f93e9 (patch) | |
tree | 59e7572224193e4b06d879fffb5068d7952a1e40 /lib/chef/mixin | |
parent | 134e80b01a63fa2df7a0f29e7365dd06e973aa1a (diff) | |
parent | d36473f78465d476d2dcaff3789a25a787827d58 (diff) | |
download | chef-df70293a5d79a9f51d02453ea055600fc77f93e9.tar.gz |
Merge pull request #5547 from chef/lcg/unified-integer
Core: fix Lint/UnifiedInteger cop
Diffstat (limited to 'lib/chef/mixin')
-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 6159c87948..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 ||= { - Fixnum => { :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) |