Sha256: a712d84025a6fb8e8b2bb3917934229bacbf63bafa697d9593966305ed52b641

Contents?: true

Size: 711 Bytes

Versions: 7

Compression:

Stored size: 711 Bytes

Contents

# frozen_string_literal: true

require "json"

module Whoop
  module Formatters
    module JsonFormatter
      # Format the SQL query
      # @param [String] message The SQL query
      # @param [Boolean] colorize - colorize the SQL query (default: false)
      # @return [String] The formatted SQL query
      def self.format(message, colorize: false)
        pretty_json = JSON.pretty_generate(message)
        return pretty_json unless colorize

        formatter = Rouge::Formatters::TerminalTruecolor.new
        lexer = Rouge::Lexers::JSON.new

        [
          "json:\n\n".colorize(:light_black).underline,
          formatter.format(lexer.lex(pretty_json))
        ].join
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
whoop-1.3.0 lib/whoop/formatters/json_formatter.rb
whoop-1.2.0 lib/whoop/formatters/json_formatter.rb
whoop-1.1.0 lib/whoop/formatters/json_formatter.rb
whoop-1.0.4 lib/whoop/formatters/json_formatter.rb
whoop-1.0.3 lib/whoop/formatters/json_formatter.rb
whoop-1.0.2 lib/whoop/formatters/json_formatter.rb
whoop-1.0.1 lib/whoop/formatters/json_formatter.rb