Class: FiberAudit::Reporters::JSON
- Defined in:
- lib/fiber_audit/reporters/json.rb
Overview
JSON reporter that outputs deterministic, schema-validated JSON. Calls Schema.build then Schema.validate! to enforce the contract.
Instance Method Summary collapse
-
#initialize(pretty: false) ⇒ JSON
constructor
A new instance of JSON.
- #render(result) ⇒ Object
Constructor Details
#initialize(pretty: false) ⇒ JSON
Returns a new instance of JSON.
12 13 14 15 |
# File 'lib/fiber_audit/reporters/json.rb', line 12 def initialize(pretty: false) super() @pretty = pretty end |
Instance Method Details
#render(result) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fiber_audit/reporters/json.rb', line 17 def render(result) # Build normalized primitive report hash from result protocol report_hash = Schema.build(result) # Validate the hash and return it (also freezes it) Schema.validate!(report_hash) json_string = if @pretty ::JSON.pretty_generate(report_hash) else ::JSON.generate(report_hash) end "#{json_string}\n" end |