Class: ServiceStatus

Inherits:
Component show all
Defined in:
lib/panda_motd/components/service_status.rb

Instance Attribute Summary

Attributes inherited from Component

#config, #errors, #name, #results

Instance Method Summary collapse

Methods inherited from Component

#lines_after, #lines_before

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

#processObject



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_sObject



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