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
Methods inherited from Component
Constructor Details
#initialize(motd) ⇒ ServiceStatus
Returns a new instance of ServiceStatus.
4 5 6 |
# File 'lib/panda_motd/components/service_status.rb', line 4 def initialize(motd) super(motd, 'service_status') end |
Instance Method Details
#process ⇒ Object
8 9 10 11 |
# File 'lib/panda_motd/components/service_status.rb', line 8 def process @services = @config['services'] @results = parse_services(@services) end |
#to_s ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/panda_motd/components/service_status.rb', line 13 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)| name_part = name.to_s.ljust(longest_name_size, ' ') + ':' status_part = status.to_s.colorize(service_colors[status.to_sym]) " #{name_part} #{status_part}" end.join("\n")} HEREDOC result.gsub(/\s$/, '') end |