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.



6
7
8
# File 'lib/panda_motd/components/service_status.rb', line 6

def initialize(motd)
  super(motd, "service_status")
end

Instance Method Details

#processObject

See Also:



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_sObject

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 = "    Services:\n    \#{@results.map do |(name, status)|\n    spaces = (\" \" * (longest_name_size - name.to_s.length + 1))\n    status_part = status.to_s.colorize(service_colors[status.to_sym])\n    \"  \#{name}\#{spaces}\#{status_part}\"\n  end.join(\"\\n\")}\n  HEREDOC\n\n  result.gsub(/\\s$/, \"\")\nend\n"