summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-09-08 12:01:34 -0700
committerGitHub <noreply@github.com>2020-09-08 12:01:34 -0700
commit0478c40769993dd4e07f63e2470a486edc1ba841 (patch)
treea8348ab4d23eaaf6ec43ee3adfb8abef5d0ecac2
parent80737ed68405edc8616b7bbe21f7cf0beb33c56f (diff)
parent08347833c30a20799c3a4b7240d8e712f23c2ca3 (diff)
downloadohai-0478c40769993dd4e07f63e2470a486edc1ba841.tar.gz
Merge pull request #1507 from chef/chefstyle
Resolve new chefstyle warnings & use safe navigators
-rw-r--r--lib/ohai/plugins/linux/network.rb12
-rw-r--r--lib/ohai/plugins/softlayer.rb2
-rw-r--r--lib/ohai/plugins/solaris2/network.rb12
3 files changed, 12 insertions, 14 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 1d01d0d8..1f8b8693 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -141,12 +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|
- if iv[:routes]
- iv[:routes].collect do |r|
- r.merge(dev: i) if r[:family] == family[:name]
- end.compact
- end
- end.compact.flatten
+ next unless iv[:routes]
+
+ iv[:routes].collect 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
# determine layer 1 details for the interface using ethtool
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 00a37ebe..fd59615f 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