class ConsoleUtils::JSONOutput::BaseFormatter
The abstract singleton class for a prettified JSON formatting.
Public Instance Methods
call(body) { || ... }
click to toggle source
Prints formatted JSON to stdout.
# File lib/console_utils/json_output/base_formatter.rb, line 8 def call(body) # :yields: formatted = format_with_fallback(body) if block_given? yield(formatted) else puts formatted end end
format(body)
click to toggle source
Formats a given JSON string
# File lib/console_utils/json_output/base_formatter.rb, line 18 def format(body) raise NotImplementedError end
format_with_fallback(body)
click to toggle source
# File lib/console_utils/json_output/base_formatter.rb, line 22 def format_with_fallback(body) format(body) rescue ParseError => error warn error return body.to_s end