diff options
author | Tim Smith <tsmith84@gmail.com> | 2021-12-31 23:37:21 -0500 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2021-12-31 23:37:21 -0500 |
commit | 8856702f3f83570ac466dc016b3aba005f8b3949 (patch) | |
tree | f4309fbdfbef78e740aa7127634092f0ddfeb7fd /knife | |
parent | bb6116d12fbc75dbb3d1daa36b8413b1bc6638d1 (diff) | |
download | chef-8856702f3f83570ac466dc016b3aba005f8b3949.tar.gz |
Resolve Style/SelectByRegexp warningsStyle_SelectByRegexp
Simplify how we collect or reject data based on regex matches
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'knife')
-rw-r--r-- | knife/lib/chef/knife/acl_bulk_add.rb | 2 | ||||
-rw-r--r-- | knife/lib/chef/knife/acl_bulk_remove.rb | 2 | ||||
-rw-r--r-- | knife/lib/chef/knife/core/subcommand_loader.rb | 2 | ||||
-rw-r--r-- | knife/spec/knife_spec_helper.rb | 4 |
4 files changed, 5 insertions, 5 deletions
diff --git a/knife/lib/chef/knife/acl_bulk_add.rb b/knife/lib/chef/knife/acl_bulk_add.rb index 4992fe2afa..bdd2e0fdc4 100644 --- a/knife/lib/chef/knife/acl_bulk_add.rb +++ b/knife/lib/chef/knife/acl_bulk_add.rb @@ -56,7 +56,7 @@ class Chef objects_to_modify = [] all_objects = rest.get_rest(object_type) - objects_to_modify = all_objects.keys.select { |object_name| object_name =~ object_name_matcher } + objects_to_modify = all_objects.keys.grep(object_name_matcher) if objects_to_modify.empty? ui.info "No #{object_type} match the expression /#{regex}/" diff --git a/knife/lib/chef/knife/acl_bulk_remove.rb b/knife/lib/chef/knife/acl_bulk_remove.rb index 0f35f1e2fb..fce76f250d 100644 --- a/knife/lib/chef/knife/acl_bulk_remove.rb +++ b/knife/lib/chef/knife/acl_bulk_remove.rb @@ -61,7 +61,7 @@ class Chef objects_to_modify = [] all_objects = rest.get_rest(object_type) - objects_to_modify = all_objects.keys.select { |object_name| object_name =~ object_name_matcher } + objects_to_modify = all_objects.keys.grep(object_name_matcher) if objects_to_modify.empty? ui.info "No #{object_type} match the expression /#{regex}/" diff --git a/knife/lib/chef/knife/core/subcommand_loader.rb b/knife/lib/chef/knife/core/subcommand_loader.rb index ca7bfcd008..d70ba11a59 100644 --- a/knife/lib/chef/knife/core/subcommand_loader.rb +++ b/knife/lib/chef/knife/core/subcommand_loader.rb @@ -184,7 +184,7 @@ class Chef # @return [Array<String>] # def positional_arguments(args) - args.select { |arg| arg =~ /^(([[:alnum:]])[[:alnum:]\_\-]+)$/ } + args.grep(/^(([[:alnum:]])[[:alnum:]\_\-]+)$/) end # Returns an Array of paths to knife commands located in diff --git a/knife/spec/knife_spec_helper.rb b/knife/spec/knife_spec_helper.rb index 7395d2759b..5a3c0761d5 100644 --- a/knife/spec/knife_spec_helper.rb +++ b/knife/spec/knife_spec_helper.rb @@ -78,8 +78,8 @@ require "spec/support/shared/matchers/match_environment_variable" # Excludes support/platforms by default # Do not change the gsub. Dir["spec/support/**/*.rb"] - .reject { |f| f =~ %r{^spec/support/platforms} } - .reject { |f| f =~ %r{^spec/support/pedant} } + .grep_v(%r{^spec/support/platforms}) + .grep_v(%r{^spec/support/pedant}) .map { |f| f.gsub(/.rb$/, "") } .map { |f| f.gsub(%r{spec/}, "") } .each { |f| require f } |