Class: RubyPgExtras::DiagnosePrint

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_pg_extras/diagnose_print.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(data) ⇒ Object



7
8
9
# File 'lib/ruby_pg_extras/diagnose_print.rb', line 7

def self.call(data)
  new.call(data)
end

Instance Method Details

#call(data) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_pg_extras/diagnose_print.rb', line 11

def call(data)
  rows = data.sort do |el|
    el.fetch(:ok) ? 1 : -1
  end.map do |el|
    symbol = el.fetch(:ok) ? "" : "x"
    color = el.fetch(:ok) ? :green : :red

    [
      colorize("[#{symbol}] - #{el.fetch(:check_name)}", color),
      colorize(el.fetch(:message), color)
    ]
  end

  puts Terminal::Table.new(
    title: title,
    rows: rows
  )
end