Module: Moult::Formatters::Json

Defined in:
lib/moult/formatters/json.rb

Overview

Emits the typed JSON output contract (schema/hotspots.schema.json). Renders straight from Report#to_h; only presentation concerns (limiting) live here, so the serialized shape can never drift from the result model.

Class Method Summary collapse

Class Method Details

.render(report, limit: nil) ⇒ String

Returns pretty-printed JSON.

Parameters:

  • report (Report)
  • limit (Integer, nil) (defaults to: nil)

    keep only the top N hotspots

Returns:

  • (String)

    pretty-printed JSON



16
17
18
19
20
# File 'lib/moult/formatters/json.rb', line 16

def render(report, limit: nil)
  data = report.to_h
  data[:hotspots] = data[:hotspots].first(limit) if limit
  JSON.pretty_generate(data)
end