Sha256: a427f1a13124d2a9bab96ccc69c830d07b2e12e715c2771e3da32810905cfe67

Contents?: true

Size: 901 Bytes

Versions: 16

Compression:

Stored size: 901 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

16 entries across 16 versions & 1 rubygems

Version Path
ruby-pg-extras-5.6.7 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.6.6 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.6.5 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.6.4 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.6.3 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.6.2 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.6.1 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.6.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.5.1 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.5.0 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.4.5 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.4.4 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.4.3 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.4.2 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.4.1 lib/ruby_pg_extras/diagnose_print.rb
ruby-pg-extras-5.4.0 lib/ruby_pg_extras/diagnose_print.rb