Skip to content

Commit

Permalink
Simplify things with &.
Browse files Browse the repository at this point in the history
We can avoid some duplicate checks by using &. in places

Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Sep 8, 2020
1 parent fe80025 commit 149f7bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
8 changes: 3 additions & 5 deletions lib/ohai/plugins/linux/network.rb
Expand Up @@ -141,11 +141,9 @@ def check_routing_table(family, iface, default_route_table)
# using a temporary var to hold routes and their interface name
def parse_routes(family, iface)
iface.collect do |i, iv|
if iv[:routes]
iv[:routes].collect do |r|
r.merge(dev: i) if r[:family] == family[:name]
end.compact
end
iv[:routes]&.collect do |r|
r.merge(dev: i) if r[:family] == family[:name]
end&.compact
end.compact.flatten
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/softlayer.rb
Expand Up @@ -39,7 +39,7 @@ def looks_like_softlayer?
logger.trace("Plugin Softlayer: looks_like_softlayer? == true")
metadata = fetch_metadata
softlayer Mash.new
metadata.each { |k, v| softlayer[k] = v } if metadata
metadata&.each { |k, v| softlayer[k] = v }
else
logger.trace("Plugin Softlayer: looks_like_softlayer? == false")
end
Expand Down
12 changes: 5 additions & 7 deletions lib/ohai/plugins/solaris2/network.rb
Expand Up @@ -86,7 +86,7 @@ def arpname_to_ifname(iface, arpname)

def full_interface_name(iface, part_name, index)
iface.each do |name, attrs|
next unless attrs && attrs.respond_to?(:[])
next unless attrs&.respond_to?(:[])
return name if /^#{part_name}($|:)/.match(name) && attrs[:index] == index
end

Expand Down Expand Up @@ -155,12 +155,10 @@ def full_interface_name(iface, part_name, index)
break
end
end
if iface[ifn][:arp]
iface[ifn][:arp].each_key do |addr|
if addr.eql?(iaddr)
iface[ifn][:addresses][iface[ifn][:arp][iaddr]] = { "family" => "lladdr" }
break
end
iface[ifn][:arp]&.each_key do |addr|
if addr.eql?(iaddr)
iface[ifn][:addresses][iface[ifn][:arp][iaddr]] = { "family" => "lladdr" }
break
end
end
end
Expand Down

0 comments on commit 149f7bd

Please sign in to comment.