diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-09-08 11:51:33 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-09-08 11:51:33 -0700 |
commit | 08347833c30a20799c3a4b7240d8e712f23c2ca3 (patch) | |
tree | e6758a87aec305785b6c529079748a788f54f77f | |
parent | 3485634758d5a5e16e3a579a77b6d18a1fab5176 (diff) | |
download | ohai-08347833c30a20799c3a4b7240d8e712f23c2ca3.tar.gz |
Bail out early to avoid safe operatorchefstyle
Also add some notes here that we should convert this to a filter_map
when we can as that's easier to read and faster.
Perf benchmarks from the tubes:
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index 0f5c8c02..0858c1a9 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -141,10 +141,12 @@ 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| - iv[:routes]&.collect do |r| + next unless iv[:routes] + + iv[:routes].collect do |r| r.merge(dev: i) if r[:family] == family[:name] - end&.compact - end.compact.flatten + 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 # determine layer 1 details for the interface using ethtool |