diff options
author | Collin McNeese <cmcneese@chef.io> | 2021-02-19 13:43:15 -0600 |
---|---|---|
committer | Collin McNeese <cmcneese@chef.io> | 2021-02-19 13:43:15 -0600 |
commit | 7afd8cf17b3c27f07cbab6b1da1124fdfbfced6b (patch) | |
tree | 54c9e4fd1090da9324a3188136e4a6eec95d45f1 | |
parent | 5944158589d0640700934c93e63c946650b10f19 (diff) | |
download | ohai-7afd8cf17b3c27f07cbab6b1da1124fdfbfced6b.tar.gz |
updates for habitat plugin from PR recommendations
Signed-off-by: Collin McNeese <cmcneese@chef.io>
-rw-r--r-- | lib/ohai/plugins/habitat.rb | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/ohai/plugins/habitat.rb b/lib/ohai/plugins/habitat.rb index 9dad5032..7a50a2c0 100644 --- a/lib/ohai/plugins/habitat.rb +++ b/lib/ohai/plugins/habitat.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true # +# Copyright:: Copyright (c) Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +20,7 @@ Ohai.plugin(:Habitat) do provides "habitat" def habitat_binary - which("hab") + @habitat_binary ||= which("hab") end def fetch_habitat_version @@ -38,18 +39,16 @@ Ohai.plugin(:Habitat) do # package type desired state elapsed (s) pid group # core/httpd/2.4.35/20190307151146 standalone up up 158169 1410 httpd.default @services = [] - lines = status_stdout.split("\n") - lines.each do |line| - @service = {} + status_stdout.each_line do |line| fields = line.split(/\s+/) next unless fields[0].match?(%r{.*/.*/.*/.*}) # ignore header line - @service = {} - @service[:identity] = fields[0] - @service[:topology] = fields[1] - @service[:state_desired] = fields[2] - @service[:state_actual] = fields[2] - (@services).push(@service) + service = {} + service[:identity] = fields[0] + service[:topology] = fields[1] + service[:state_desired] = fields[2] + service[:state_actual] = fields[2] + (@services).push(service) end @services end |