Sha256: e71c1129c0b60b3cac76dd811ccb426f8c7bd9f31b1896d3263d44966a692a48
Contents?: true
Size: 1.45 KB
Versions: 8
Compression:
Stored size: 1.45 KB
Contents
module Invoker class ProcessPrinter MAX_COLUMN_WIDTH = 40 def self.to_json(workers) final_json = [] Invoker::CONFIG.processes.each do |process| if worker = workers[process.label] final_json << { :command => process.cmd, :command_label => process.label, :dir => process.dir, :pid => worker.pid } else final_json << { :command => process.cmd, :command_label => process.label, :dir => process.dir } end end final_json.to_json end def self.print_table(json_data) final_json = JSON.parse(json_data) if final_json && !final_json.empty? json_for_printing = [] final_json.each do |json_row| if json_row["pid"] json_for_printing << colorize_hash(json_row, "green") else json_row["pid"] = "[light_black]not running[/]" json_for_printing << colorize_hash(json_row, "light_black") end end Formatador.display_compact_table(json_for_printing) end end private def self.colorize_hash(hash, color) hash.inject({}) do |mem,(key,obj)| if obj.to_s.length > MAX_COLUMN_WIDTH short_command = "#{obj.to_s[0..MAX_COLUMN_WIDTH]}.." mem[key] = "[#{color}]#{short_command}[/]" else mem[key] = "[#{color}]#{obj}[/]" end mem end end end end
Version data entries
8 entries across 8 versions & 1 rubygems