summaryrefslogtreecommitdiff
path: root/lib/chef/provider/ifconfig.rb
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-06-11 15:02:42 -0700
committerTim Smith <tsmith84@gmail.com>2020-06-11 15:32:53 -0700
commit5825eea4b139b9af089c3075d042d5d3160583ec (patch)
treefd79641ded1857ee4166b6e9ba774a35ab47b06b /lib/chef/provider/ifconfig.rb
parent3889eddfc9944b23caea412d05c08b9b156cb50f (diff)
downloadchef-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 'lib/chef/provider/ifconfig.rb')
-rw-r--r--lib/chef/provider/ifconfig.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb
index 79f5bb78fe..cfabe292f9 100644
--- a/lib/chef/provider/ifconfig.rb
+++ b/lib/chef/provider/ifconfig.rb
@@ -59,12 +59,12 @@ class Chef
@net_tools_version = shell_out("ifconfig", "--version")
@net_tools_version.stdout.each_line do |line|
- if line =~ /^net-tools (\d+\.\d+)/
+ if /^net-tools (\d+\.\d+)/.match?(line)
@ifconfig_version = line.match(/^net-tools (\d+\.\d+)/)[1]
end
end
@net_tools_version.stderr.each_line do |line|
- if line =~ /^net-tools (\d+\.\d+)/
+ if /^net-tools (\d+\.\d+)/.match?(line)
@ifconfig_version = line.match(/^net-tools (\d+\.\d+)/)[1]
end
end
@@ -88,11 +88,11 @@ class Chef
@int_name = line[0..9].strip
@interfaces[@int_name] = { "hwaddr" => (line =~ /(HWaddr)/ ? ($') : "nil").strip.chomp }
else
- @interfaces[@int_name]["inet_addr"] = (line =~ /inet addr:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /inet addr:/
- @interfaces[@int_name]["bcast"] = (line =~ /Bcast:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /Bcast:/
- @interfaces[@int_name]["mask"] = (line =~ /Mask:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /Mask:/
- @interfaces[@int_name]["mtu"] = (line =~ /MTU:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /MTU:/
- @interfaces[@int_name]["metric"] = (line =~ /Metric:(\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /Metric:/
+ @interfaces[@int_name]["inet_addr"] = (line =~ /inet addr:(\S+)/ ? Regexp.last_match(1) : "nil") if /inet addr:/.match?(line)
+ @interfaces[@int_name]["bcast"] = (line =~ /Bcast:(\S+)/ ? Regexp.last_match(1) : "nil") if /Bcast:/.match?(line)
+ @interfaces[@int_name]["mask"] = (line =~ /Mask:(\S+)/ ? Regexp.last_match(1) : "nil") if /Mask:/.match?(line)
+ @interfaces[@int_name]["mtu"] = (line =~ /MTU:(\S+)/ ? Regexp.last_match(1) : "nil") if /MTU:/.match?(line)
+ @interfaces[@int_name]["metric"] = (line =~ /Metric:(\S+)/ ? Regexp.last_match(1) : "nil") if /Metric:/.match?(line)
end
next unless @interfaces.key?(new_resource.device)