Class: ServiceStatus
- Defined in:
- lib/panda_motd/components/service_status.rb
Instance Attribute Summary
Attributes inherited from Component
#config, #errors, #name, #results
Instance Method Summary collapse
-
#initialize(motd) ⇒ ServiceStatus
constructor
A new instance of ServiceStatus.
- #process ⇒ Object
-
#to_s ⇒ Object
Gets a printable string to be printed in the MOTD.
Methods inherited from Component
Constructor Details
#initialize(motd) ⇒ ServiceStatus
Returns a new instance of ServiceStatus.
6 7 8 |
# File 'lib/panda_motd/components/service_status.rb', line 6 def initialize(motd) super(motd, "service_status") end |
Instance Method Details
#process ⇒ Object
11 12 13 14 |
# File 'lib/panda_motd/components/service_status.rb', line 11 def process @services = @config["services"] @results = parse_services(@services) end |
#to_s ⇒ Object
Gets a printable string to be printed in the MOTD. If there are no services found in the result, it prints a warning message.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/panda_motd/components/service_status.rb', line 18 def to_s return "Services:\n No matching services found." unless @results.any? longest_name_size = @results.keys.map { |k| k.to_s.length }.max result = <<~HEREDOC Services: #{@results.map do |(name, status)| spaces = (" " * (longest_name_size - name.to_s.length + 1)) status_part = status.to_s.colorize(service_colors[status.to_sym]) " #{name}#{spaces}#{status_part}" end.join("\n")} HEREDOC result.gsub(/\s$/, "") end |