diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-10-16 09:50:01 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-10-16 09:50:01 -0700 |
commit | 0b26c901cf3fa8a3e32e4a3f513864bc2d959e04 (patch) | |
tree | b5a3091a06d4df36c9c32b628b74463058ff1849 /lib/chef | |
parent | 8c67bf7746301cb73dea14917a7a91f92a37eb13 (diff) | |
download | chef-0b26c901cf3fa8a3e32e4a3f513864bc2d959e04.tar.gz |
Avoid declaring arrays in loops
There's still a few of these left over, but these are the easy wins with obvious wins.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/provider/registry_key.rb | 7 | ||||
-rw-r--r-- | lib/chef/provider/service/debian.rb | 3 | ||||
-rw-r--r-- | lib/chef/resource/registry_key.rb | 4 |
3 files changed, 9 insertions, 5 deletions
diff --git a/lib/chef/provider/registry_key.rb b/lib/chef/provider/registry_key.rb index d1849066f8..316a2a1081 100644 --- a/lib/chef/provider/registry_key.rb +++ b/lib/chef/provider/registry_key.rb @@ -35,6 +35,8 @@ class Chef include Chef::Mixin::Checksum + WORD_TYPES = %i{dword dword_big_endian qword}.freeze + def running_on_windows! unless ChefUtils.windows? raise Chef::Exceptions::Win32NotWindows, "Attempt to manipulate the windows registry on a non-windows node" @@ -122,9 +124,8 @@ class Chef new_resource.unscrubbed_values.each do |value| if @name_hash.key?(value[:name].downcase) current_value = @name_hash[value[:name].downcase] - if %i{dword dword_big_endian qword}.include? value[:type] - value[:data] = value[:data].to_i - end + value[:data] = value[:data].to_i if WORD_TYPES.include?(value[:type]) + unless current_value[:type] == value[:type] && current_value[:data] == value[:data] converge_by_value = if new_resource.sensitive value.merge(data: "*sensitive value suppressed*") diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb index da599fa2f6..17e0b19b9c 100644 --- a/lib/chef/provider/service/debian.rb +++ b/lib/chef/provider/service/debian.rb @@ -28,6 +28,7 @@ class Chef UPDATE_RC_D_ENABLED_MATCHES = %r{/rc[\dS].d/S|not installed}i.freeze UPDATE_RC_D_PRIORITIES = %r{/rc([\dS]).d/([SK])(\d\d)}i.freeze + RUNLEVELS = %w{ 1 2 3 4 5 S }.freeze def self.supports?(resource, action) service_script_exist?(:initd, resource.service_name) @@ -121,7 +122,7 @@ class Chef priority.each do |runlevel, arguments| logger.trace("#{new_resource} runlevel #{runlevel}, action #{arguments[0]}, priority #{arguments[1]}") # if we are in a update-rc.d default startup runlevel && we start in this runlevel - if %w{ 1 2 3 4 5 S }.include?(runlevel) && arguments[0] == :start + if RUNLEVELS.include?(runlevel) && arguments[0] == :start enabled = true end end diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb index ae8fcc3688..7e51ea1ef6 100644 --- a/lib/chef/resource/registry_key.rb +++ b/lib/chef/resource/registry_key.rb @@ -71,6 +71,8 @@ class Chef property :key, String, name_property: true + VALID_VALUE_HASH_KEYS = %i{name type data}.freeze + def values(arg = nil) if not arg.nil? if arg.is_a?(Hash) @@ -88,7 +90,7 @@ class Chef raise ArgumentError, "Missing name key in RegistryKey values hash" unless v.key?(:name) v.each_key do |key| - raise ArgumentError, "Bad key #{key} in RegistryKey values hash" unless %i{name type data}.include?(key) + raise ArgumentError, "Bad key #{key} in RegistryKey values hash" unless VALID_VALUE_HASH_KEYS.include?(key) end raise ArgumentError, "Type of name => #{v[:name]} should be string" unless v[:name].is_a?(String) |