From e2dd316c2380bd2a06c8bf928357169e089a401e Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 21 Apr 2021 20:17:01 -0700 Subject: Use filter_map where we can We only support Ruby 2.7+ and this takes less memory Signed-off-by: Tim Smith --- lib/ohai/plugins/cloud.rb | 4 ++-- lib/ohai/plugins/linux/network.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb index be7a8405..8e79a824 100644 --- a/lib/ohai/plugins/cloud.rb +++ b/lib/ohai/plugins/cloud.rb @@ -149,9 +149,9 @@ Ohai.plugin(:Cloud) do end end.flatten.compact - private_ips = gce["instance"]["networkInterfaces"].collect do |interface| + private_ips = gce["instance"]["networkInterfaces"].filter_map do |interface| interface["ip"] - end.compact + end public_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :public) } private_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :private) } diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index 713b9c16..80168e39 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -141,13 +141,13 @@ Ohai.plugin(:Network) do # using a temporary var to hold routes and their interface name def parse_routes(family, iface) - iface.collect do |i, iv| + iface.filter_map do |i, iv| next unless iv[:routes] - iv[:routes].collect do |r| + iv[:routes].filter_map do |r| r.merge(dev: i) if r[:family] == family[:name] - end.compact # @todo: when we drop ruby 2.6 this should be a filter_map - end.compact.flatten # @todo: when we drop ruby 2.6 this should be a filter_map + end + end.flatten end # determine layer 1 details for the interface using ethtool -- cgit v1.2.1