Class: ConsoleUtils::JSONOutput::DefaultFormatter

Inherits:
BaseFormatter
  • Object
show all
Defined in:
lib/console_utils/json_output/default_formatter.rb

Overview

The default formatter uses standart JSON library to output prettified JSON

Instance Method Summary collapse

Methods inherited from BaseFormatter

#call, #format_with_fallback

Instance Method Details

#format(body) ⇒ Object

:nodoc:


5
6
7
8
9
10
# File 'lib/console_utils/json_output/default_formatter.rb', line 5

def format(body) #:nodoc:
  JSON.pretty_generate JSON(body), :allow_nan => true, :max_nesting => false
rescue JSON::ParseError, JSON::GeneratorError
  error = $!
  raise ParseError, "#{error.class.to_s}: #{error.message}"
end