Module: Whoop::Formatters::JsonFormatter

Defined in:
lib/whoop/formatters/json_formatter.rb

Class Method Summary collapse

Class Method Details

.format(message, colorize: false) ⇒ String

Format the SQL query

Parameters:

  • message (String)

    The SQL query

  • colorize (Boolean) (defaults to: false)
    • colorize the SQL query (default: false)

Returns:

  • (String)

    The formatted SQL query



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/whoop/formatters/json_formatter.rb', line 12

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