diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-10-27 10:51:51 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-10-27 10:51:51 -0700 |
commit | 5122f9f77f89ba026e77b36062b70b241c552792 (patch) | |
tree | 75a930f73e58e84a91707b10d86148af8b1a55a8 | |
parent | b3dbca14e1b587f4367acf082392fb3aea7bb872 (diff) | |
download | chef-5122f9f77f89ba026e77b36062b70b241c552792.tar.gz |
Merge repetitive conditionals
So much easier to read and probably faster this way too.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | chef-utils/spec/unit/dsl/which_spec.rb | 2 | ||||
-rw-r--r-- | lib/chef/chef_fs/data_handler/cookbook_data_handler.rb | 2 | ||||
-rw-r--r-- | lib/chef/chef_fs/file_pattern.rb | 2 | ||||
-rw-r--r-- | lib/chef/cookbook_manifest.rb | 2 | ||||
-rw-r--r-- | lib/chef/cookbook_version.rb | 2 | ||||
-rw-r--r-- | lib/chef/key.rb | 2 | ||||
-rw-r--r-- | lib/chef/mixin/openssl_helper.rb | 2 | ||||
-rw-r--r-- | lib/chef/property.rb | 2 | ||||
-rw-r--r-- | lib/chef/win32/security/sid.rb | 2 | ||||
-rw-r--r-- | spec/support/lib/chef/resource/cat.rb | 2 | ||||
-rw-r--r-- | spec/support/lib/chef/resource/one_two_three_four.rb | 2 | ||||
-rw-r--r-- | spec/unit/mixin/which.rb | 2 |
12 files changed, 12 insertions, 12 deletions
diff --git a/chef-utils/spec/unit/dsl/which_spec.rb b/chef-utils/spec/unit/dsl/which_spec.rb index 941f6282a0..96e6296e5a 100644 --- a/chef-utils/spec/unit/dsl/which_spec.rb +++ b/chef-utils/spec/unit/dsl/which_spec.rb @@ -94,7 +94,7 @@ RSpec.describe ChefUtils::DSL::Which do end test_which("arrays with blocks", "foo1", "foo2", finds: "/dir2/foo1", others: [ "/dir1/foo2" ]) do |f| - raise "bad arg to block" unless f == "/dir2/foo1" || f == "/dir1/foo2" + raise "bad arg to block" unless ["/dir2/foo1", "/dir1/foo2"].include?(f) true end diff --git a/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb b/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb index 222e6069f3..ee1480c62e 100644 --- a/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb @@ -24,7 +24,7 @@ class Chef end def preserve_key?(key) - key == "cookbook_name" || key == "version" + %w{cookbook_name version}.include?(key) end def chef_class diff --git a/lib/chef/chef_fs/file_pattern.rb b/lib/chef/chef_fs/file_pattern.rb index 163319032b..37e72f379b 100644 --- a/lib/chef/chef_fs/file_pattern.rb +++ b/lib/chef/chef_fs/file_pattern.rb @@ -204,7 +204,7 @@ class Chef end # Skip // and /./ (pretend it's not there) - if exact == "" || exact == "." + if ["", "."].include?(exact) next end diff --git a/lib/chef/cookbook_manifest.rb b/lib/chef/cookbook_manifest.rb index 765133b49a..6e79a880e9 100644 --- a/lib/chef/cookbook_manifest.rb +++ b/lib/chef/cookbook_manifest.rb @@ -282,7 +282,7 @@ class Chef name = File.join(segment, pathname.basename.to_s) - if segment == "templates" || segment == "files" + if %w{templates files}.include?(segment) # Check if pathname looks like files/foo or templates/foo (unscoped) if pathname.each_filename.to_a.length == 2 # Use root_default in case the same path exists at root_default and default diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 62407aa314..135a5292a6 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -264,7 +264,7 @@ class Chef if found_pref manifest_records_by_path[found_pref] else - if segment == :files || segment == :templates + if %i{files templates}.include?(segment) error_message = "Cookbook '#{name}' (#{version}) does not contain a file at any of these locations:\n" error_locations = if filename.is_a?(Array) filename.map { |name| " #{File.join(segment.to_s, name)}" } diff --git a/lib/chef/key.rb b/lib/chef/key.rb index 6d30c97ad1..f1c046e6ba 100644 --- a/lib/chef/key.rb +++ b/lib/chef/key.rb @@ -46,7 +46,7 @@ class Chef # Actor that the key is for, either a client or a user. @actor = actor - unless actor_field_name == "user" || actor_field_name == "client" + unless %w{user client}.include?(actor_field_name) raise Chef::Exceptions::InvalidKeyArgument, "the second argument to initialize must be either 'user' or 'client'" end diff --git a/lib/chef/mixin/openssl_helper.rb b/lib/chef/mixin/openssl_helper.rb index 1d50523df8..69583bea98 100644 --- a/lib/chef/mixin/openssl_helper.rb +++ b/lib/chef/mixin/openssl_helper.rb @@ -155,7 +155,7 @@ class Chef # @return [OpenSSL::PKey::DH] def gen_ec_priv_key(curve) raise TypeError, "curve must be a string" unless curve.is_a?(String) - raise ArgumentError, "Specified curve is not available on this system" unless curve == "prime256v1" || curve == "secp384r1" || curve == "secp521r1" + raise ArgumentError, "Specified curve is not available on this system" unless %w{prime256v1 secp384r1 secp521r1}.include?(curve) ::OpenSSL::PKey::EC.new(curve).generate_key end diff --git a/lib/chef/property.rb b/lib/chef/property.rb index 819b82f384..bbf06854d6 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -559,7 +559,7 @@ class Chef if modified_options.key?(:name_property) || modified_options.key?(:name_attribute) || modified_options.key?(:default) - options = options.reject { |k, v| k == :name_attribute || k == :name_property || k == :default } + options = options.reject { |k, v| %i{name_attribute name_property default}.include?(k) } end self.class.new(**options.merge(modified_options)) end diff --git a/lib/chef/win32/security/sid.rb b/lib/chef/win32/security/sid.rb index ed6c7bd65d..aaf3532fc4 100644 --- a/lib/chef/win32/security/sid.rb +++ b/lib/chef/win32/security/sid.rb @@ -321,7 +321,7 @@ class Chef while status == ERROR_MORE_DATA status = NetUserEnum(servername, level, filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle) - if status == NERR_Success || status == ERROR_MORE_DATA + if [NERR_Success, ERROR_MORE_DATA].include?(status) Array.new(entriesread.read_long) do |i| user_info = USER_INFO_3.new(bufptr.read_pointer + i * USER_INFO_3.size) # Check if the account is the Administrator account diff --git a/spec/support/lib/chef/resource/cat.rb b/spec/support/lib/chef/resource/cat.rb index a66aef8e19..f81504d167 100644 --- a/spec/support/lib/chef/resource/cat.rb +++ b/spec/support/lib/chef/resource/cat.rb @@ -29,7 +29,7 @@ class Chef end def pretty_kitty(arg = nil) - if arg == true || arg == false + if [true, false].include?(arg) @pretty_kitty = arg end @pretty_kitty diff --git a/spec/support/lib/chef/resource/one_two_three_four.rb b/spec/support/lib/chef/resource/one_two_three_four.rb index 4dcbf1e60b..da95d329f5 100644 --- a/spec/support/lib/chef/resource/one_two_three_four.rb +++ b/spec/support/lib/chef/resource/one_two_three_four.rb @@ -26,7 +26,7 @@ class Chef end def something(arg = nil) - if arg == true || arg == false + if [true, false].include?(arg) @something = arg end @something diff --git a/spec/unit/mixin/which.rb b/spec/unit/mixin/which.rb index 60af349a62..a0030a5c51 100644 --- a/spec/unit/mixin/which.rb +++ b/spec/unit/mixin/which.rb @@ -93,7 +93,7 @@ describe Chef::Mixin::Which do end test_which("arrays with blocks", "foo1", "foo2", finds: "/dir2/foo1", others: [ "/dir1/foo2" ]) do |f| - raise "bad arg to block" unless f == "/dir2/foo1" || f == "/dir1/foo2" + raise "bad arg to block" unless ["/dir2/foo1", "/dir1/foo2"].include?(f) true end |