diff options
-rw-r--r-- | .rubocop.yml | 3 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 8 |
2 files changed, 7 insertions, 4 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index f1e7a135..e948a583 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,3 +10,6 @@ Layout/Tab: Exclude: - "lib/ohai/plugins/mono.rb" - "lib/ohai/plugins/darwin/hardware.rb" + +Performance/UnneededSort: + Enabled: true diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index 1616d8a7..73a922d5 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -388,9 +388,9 @@ Ohai.plugin(:Network) do def choose_default_route(routes) routes.select do |r| r[:destination] == "default" - end.sort do |x, y| + end.min do |x, y| (x[:metric].nil? ? 0 : x[:metric].to_i) <=> (y[:metric].nil? ? 0 : y[:metric].to_i) - end.first + end end def interface_has_no_addresses_in_family?(iface, family) @@ -447,7 +447,7 @@ Ohai.plugin(:Network) do iface[r[:dev]][:state] == "up" && route_is_valid_default_route?(r, default_route) end - end.sort_by do |r| + end.min_by do |r| # sorting the selected routes: # - getting default routes first # - then sort by metric @@ -463,7 +463,7 @@ Ohai.plugin(:Network) do 0 end, ] - end.first + end end # Both the network plugin and this plugin (linux/network) are run on linux. This plugin runs first. |