summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-08-03 18:57:52 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-03 18:57:52 -0700
commit5b52fcb1da3e8b137cfb50dc90ae378b5983a701 (patch)
treecd950e57377fe28bf3be578cebf8c21435d08d89
parente37c22f8f4162ba98e7746ef3fb16dab07bbf8b2 (diff)
downloadohai-rubocop_Performance_Detect.tar.gz
Use .find instead of .select.firstrubocop_Performance_Detect
Avoid creating and object we don't need. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/linux/network.rb2
-rw-r--r--lib/ohai/plugins/network.rb4
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index f5543819..0e24c88f 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -478,7 +478,7 @@ Ohai.plugin(:Network) do
# returns the macaddress for interface from a hash of interfaces (iface elsewhere in this file)
def get_mac_for_interface(interfaces, interface)
- interfaces[interface][:addresses].select { |k, v| v["family"] == "lladdr" }.first.first unless interfaces[interface][:addresses].nil? || interfaces[interface][:flags].include?("NOARP")
+ interfaces[interface][:addresses].find { |k, v| v["family"] == "lladdr" }.first unless interfaces[interface][:addresses].nil? || interfaces[interface][:flags].include?("NOARP")
end
# returns the default route with the lowest metric (unspecified metric is 0)
diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb
index 8e9425ef..c1b15ced 100644
--- a/lib/ohai/plugins/network.rb
+++ b/lib/ohai/plugins/network.rb
@@ -88,9 +88,9 @@ Ohai.plugin(:NetworkAddresses) do
r = gw_if_ips.first
else
# checking network masks
- r = gw_if_ips.select do |v|
+ r = gw_if_ips.find do |v|
network_contains_address(network[gw_attr], v[:ipaddress], v[:iface])
- end.first
+ end
if r.nil?
r = gw_if_ips.first
logger.trace("Plugin Network: [#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}")