summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-08-03 15:21:16 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-03 16:23:27 -0700
commit9a6ac264ade2ca205b00e4247c7c2d4d8d757f4a (patch)
treeb1d2192c5a04fa6920d92a30c00ca35d883fa98a
parentc202ce4e318a6bc842158970aeb6b3d13fa6a0df (diff)
downloadchef-9a6ac264ade2ca205b00e4247c7c2d4d8d757f4a.tar.gz
Use .key? instead of keys.include
We don't need to create an array that we then search when we can just search the hash. Also disable a few hash like calls that are false positives Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/property.rb2
-rw-r--r--lib/chef/provider/template/content.rb1
-rw-r--r--lib/chef/provider/user/dscl.rb4
-rw-r--r--lib/chef/resource.rb2
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"