diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-06-11 15:02:42 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-06-11 15:32:53 -0700 |
commit | 5825eea4b139b9af089c3075d042d5d3160583ec (patch) | |
tree | fd79641ded1857ee4166b6e9ba774a35ab47b06b /chef-config | |
parent | 3889eddfc9944b23caea412d05c08b9b156cb50f (diff) | |
download | chef-5825eea4b139b9af089c3075d042d5d3160583ec.tar.gz |
Use .match? not =~ when match values aren't necessary
Autocorrected from RuboCop Performance which is now smart enough to detect when you use the match and when you don't. Using match? does not create any objects so it's slightly faster and uses less memory.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'chef-config')
-rw-r--r-- | chef-config/lib/chef-config/config.rb | 6 | ||||
-rw-r--r-- | chef-config/lib/chef-config/path_helper.rb | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index 7fc2e2c91e..bbf686af18 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -450,7 +450,7 @@ module ChefConfig default :repo_mode do if local_mode && !chef_zero.osc_compat "hosted_everything" - elsif chef_server_url =~ %r{/+organizations/.+} + elsif %r{/+organizations/.+}.match?(chef_server_url) "hosted_everything" else "everything" @@ -506,7 +506,7 @@ module ChefConfig default(:chef_server_root) do # if the chef_server_url is a path to an organization, aka # 'some_url.../organizations/*' then remove the '/organization/*' by default - if configuration[:chef_server_url] =~ %r{/organizations/\S*$} + if %r{/organizations/\S*$}.match?(configuration[:chef_server_url]) configuration[:chef_server_url].split("/")[0..-3].join("/") elsif configuration[:chef_server_url] # default to whatever chef_server_url is configuration[:chef_server_url] @@ -1118,7 +1118,7 @@ module ChefConfig # proxy before parsing. The regex /^.*:\/\// matches, for example, http://. Reusing proxy # here since we are really just trying to get the string built correctly. proxy = unless proxy_env_var.empty? - if proxy_env_var =~ %r{^.*://} + if %r{^.*://}.match?(proxy_env_var) URI.parse(proxy_env_var) else URI.parse("#{scheme}://#{proxy_env_var}") diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb index 8429a08c1f..570e666e10 100644 --- a/chef-config/lib/chef-config/path_helper.rb +++ b/chef-config/lib/chef-config/path_helper.rb @@ -91,7 +91,7 @@ module ChefConfig def self.windows_max_length_exceeded?(path) # Check to see if paths without the \\?\ prefix are over the maximum allowed length for the Windows API # http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx - unless path =~ /^\\\\?\\/ + unless /^\\\\?\\/.match?(path) if path.length > WIN_MAX_PATH return true end @@ -103,7 +103,7 @@ module ChefConfig def self.printable?(string) # returns true if string is free of non-printable characters (escape sequences) # this returns false for whitespace escape sequences as well, e.g. \n\t - if string =~ /[^[:print:]]/ + if /[^[:print:]]/.match?(string) false else true |