diff options
author | Tim Smith <tsmith@chef.io> | 2020-08-03 16:41:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-03 16:41:57 -0700 |
commit | 16512dd672de531d7e70dd12f5609466a00eb582 (patch) | |
tree | b1d2192c5a04fa6920d92a30c00ca35d883fa98a | |
parent | c202ce4e318a6bc842158970aeb6b3d13fa6a0df (diff) | |
parent | 9a6ac264ade2ca205b00e4247c7c2d4d8d757f4a (diff) | |
download | chef-16512dd672de531d7e70dd12f5609466a00eb582.tar.gz |
Merge pull request #10246 from chef/rubocop_Performance_InefficientHashSearch
Use .key? instead of keys.include
-rw-r--r-- | lib/chef/property.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/template/content.rb | 1 | ||||
-rw-r--r-- | lib/chef/provider/user/dscl.rb | 4 | ||||
-rw-r--r-- | lib/chef/resource.rb | 2 |
4 files changed, 5 insertions, 4 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb index 720fa70dd1..819b82f384 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -706,7 +706,7 @@ class Chef # As of this writing, `name` is the only Chef::Resource property created with the # `property` definition, but this will allow for future properties to be extended # as needed. - !Chef::Resource.properties.keys.include?(name) + !Chef::Resource.properties.key?(name) end def exec_in_resource(resource, proc, *args) diff --git a/lib/chef/provider/template/content.rb b/lib/chef/provider/template/content.rb index b4d62755c2..a0977b5523 100644 --- a/lib/chef/provider/template/content.rb +++ b/lib/chef/provider/template/content.rb @@ -1,3 +1,4 @@ +# rubocop: disable Performance/InefficientHashSearch # # Author:: Lamont Granquist (<lamont@chef.io>) # Copyright:: Copyright (c) Chef Software Inc. diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index 4c056b00fd..7b86fa5269 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -562,7 +562,7 @@ in 'password', with the associated 'salt' and 'iterations'.") # Sets a value in user information hash using Chef attributes as keys. # def dscl_set(user_hash, key, value) - raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.keys.include?(key) + raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.key?(key) user_hash[DSCL_PROPERTY_MAP[key]] = [ value ] user_hash @@ -572,7 +572,7 @@ in 'password', with the associated 'salt' and 'iterations'.") # Gets a value from user information hash using Chef attributes as keys. # def dscl_get(user_hash, key) - raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.keys.include?(key) + raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.key?(key) # DSCL values are set as arrays value = user_hash[DSCL_PROPERTY_MAP[key]] diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index f2390b5801..1530243b5d 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -673,7 +673,7 @@ class Chef ivars = instance_variables.map(&:to_sym) - HIDDEN_IVARS ivars.each do |ivar| iv = ivar.to_s.sub(/^@/, "") - if all_props.keys.include?(iv) + if all_props.key?(iv) text << " #{iv} #{all_props[iv]}\n" elsif (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?) text << " #{iv} #{value_to_text(value)}\n" |