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 | |
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
-rw-r--r-- | lib/chef/application/exit_code.rb | 2 | ||||
-rw-r--r-- | lib/chef/mixin/powershell_type_coercions.rb | 38 | ||||
-rw-r--r-- | lib/chef/node/common_api.rb | 2 | ||||
-rw-r--r-- | lib/chef/resource/launchd.rb | 4 | ||||
-rw-r--r-- | lib/chef/resource/reboot.rb | 2 |
5 files changed, 24 insertions, 24 deletions
diff --git a/lib/chef/application/exit_code.rb b/lib/chef/application/exit_code.rb index b33085c95d..2c1298cf91 100644 --- a/lib/chef/application/exit_code.rb +++ b/lib/chef/application/exit_code.rb @@ -88,7 +88,7 @@ class Chef def normalize_legacy_exit_code(exit_code) case exit_code - when Fixnum + when Integer exit_code when Exception lookup_exit_code_by_exception(exit_code) 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) diff --git a/lib/chef/node/common_api.rb b/lib/chef/node/common_api.rb index 9bb83a5178..c9786807e9 100644 --- a/lib/chef/node/common_api.rb +++ b/lib/chef/node/common_api.rb @@ -24,7 +24,7 @@ class Chef # method-style access to attributes def valid_container?(obj, key) - return obj.is_a?(Hash) || (obj.is_a?(Array) && key.is_a?(Fixnum)) + return obj.is_a?(Hash) || (obj.is_a?(Array) && key.is_a?(Integer)) end private :valid_container? diff --git a/lib/chef/resource/launchd.rb b/lib/chef/resource/launchd.rb index 27937515ec..6427b13f84 100644 --- a/lib/chef/resource/launchd.rb +++ b/lib/chef/resource/launchd.rb @@ -72,8 +72,8 @@ class Chef raise Chef::Exceptions::ValidationFailed, error_msg end - unless entry.values.all? { |val| val.is_a?(Fixnum) } - failed_values = entry.values.reject { |val| val.is_a?(Fixnum) }.join(", ") + unless entry.values.all? { |val| val.is_a?(Integer) } + failed_values = entry.values.reject { |val| val.is_a?(Integer) }.join(", ") error_msg = "Invalid value(s) (#{failed_values}) for start_calendar_interval item. Values must be integers!" raise Chef::Exceptions::ValidationFailed, error_msg end diff --git a/lib/chef/resource/reboot.rb b/lib/chef/resource/reboot.rb index 24d6e74157..519defa602 100644 --- a/lib/chef/resource/reboot.rb +++ b/lib/chef/resource/reboot.rb @@ -41,7 +41,7 @@ class Chef end def delay_mins(arg = nil) - set_or_return(:delay_mins, arg, :kind_of => Fixnum) + set_or_return(:delay_mins, arg, :kind_of => Integer) end end end |