summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-09-08 10:25:26 -0700
committerTim Smith <tsmith84@gmail.com>2020-09-08 10:57:29 -0700
commit149f7bdcd52a64df91bb3dc75877999ee5349172 (patch)
tree73152ce1fb811c955c3b874259067b2c496a4982
parentfe800255fda66386c3ea96b2120b62d13a6abd69 (diff)
downloadohai-149f7bdcd52a64df91bb3dc75877999ee5349172.tar.gz
Simplify things with &.
We can avoid some duplicate checks by using &. in places Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/linux/network.rb8
-rw-r--r--lib/ohai/plugins/softlayer.rb2
-rw-r--r--lib/ohai/plugins/solaris2/network.rb12
3 files changed, 9 insertions, 13 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 54523e11..0f5c8c02 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -141,11 +141,9 @@ 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|
- 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
diff --git a/lib/ohai/plugins/softlayer.rb b/lib/ohai/plugins/softlayer.rb
index 34b2c343..fd48e9fa 100644
--- a/lib/ohai/plugins/softlayer.rb
+++ b/lib/ohai/plugins/softlayer.rb
@@ -39,7 +39,7 @@ Ohai.plugin(:Softlayer) do
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
diff --git a/lib/ohai/plugins/solaris2/network.rb b/lib/ohai/plugins/solaris2/network.rb
index 1c7ff0f1..3f15bfcd 100644
--- a/lib/ohai/plugins/solaris2/network.rb
+++ b/lib/ohai/plugins/solaris2/network.rb
@@ -86,7 +86,7 @@ Ohai.plugin(:Network) do
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
@@ -155,12 +155,10 @@ Ohai.plugin(:Network) do
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