Class: DocktorRails::Reporters::JsonReporter
- Inherits:
-
Object
- Object
- DocktorRails::Reporters::JsonReporter
- Defined in:
- lib/docktor_rails/reporters/json_reporter.rb
Constant Summary collapse
- SCHEMA_VERSION =
1
Instance Method Summary collapse
-
#initialize(io: $stdout) ⇒ JsonReporter
constructor
A new instance of JsonReporter.
- #render(report, tool_version:) ⇒ Object
Constructor Details
#initialize(io: $stdout) ⇒ JsonReporter
Returns a new instance of JsonReporter.
12 13 14 |
# File 'lib/docktor_rails/reporters/json_reporter.rb', line 12 def initialize(io: $stdout) @io = io end |
Instance Method Details
#render(report, tool_version:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/docktor_rails/reporters/json_reporter.rb', line 16 def render(report, tool_version:) platform = report[:platform] checks = report.fetch(:checks).map do |r| h = r.to_h hint = Guidance.hint_for(r, platform) h[:hint] = hint if hint && !h.key?(:hint) h end payload = { schema_version: SCHEMA_VERSION, tool: { name: "docktor_rails", version: tool_version }, context: { root: report[:root], host: platform&.to_h }, status: report.fetch(:status).to_s, summary: report.fetch(:summary), checks: checks } @io.write(JSON.pretty_generate(payload)) @io.write("\n") end |