Sha256: 181aacb88e6e132f41ec754c5c0ad9fcf32c8ea1ef6fce39cb86b6841c2bcba8

Contents?: true

Size: 899 Bytes

Versions: 33

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

require 'terminal-table'

module RubyPgExtras
  class DiagnosePrint
    def self.call(data)
      new.call(data)
    end

    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

    private

    def title
      "ruby-pg-extras - diagnose report"
    end

    def colorize(string, color)
      if color == :red
        "\e[0;31;49m#{string}\e[0m"
      elsif color == :green
        "\e[0;32;49m#{string}\e[0m"
      else
        raise "Unsupported color: #{color}"
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
ruby-pg-extras-5.3.1 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.3.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.2.5 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.2.4 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.2.3 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.2.2 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.2.1 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.2.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.1.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.0.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.13.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.12.2 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.12.1 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.12.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.11.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.10.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.9.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.8.1 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.7.2 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-4.7.1 lib/ruby_pg_extras/diagnose_print.rb