Class: Sus::Output::Structured
- Defined in:
- lib/sus/output/structured.rb
Overview
Represents a structured JSON output handler for machine-readable output.
Constant Summary
Constants included from Messages
Messages::FAILED_PREFIX, Messages::PASSED_PREFIX
Instance Attribute Summary
Attributes inherited from Null
Class Method Summary collapse
-
.buffered ⇒ Object
Create a buffered structured output handler.
Instance Method Summary collapse
-
#inform(message, identity) ⇒ Object
Output an informational message as JSON.
-
#initialize(io, identity = nil) ⇒ Structured
constructor
Initialize a new Structured output handler.
-
#skip(reason, identity) ⇒ Object
Output a skip message as JSON.
Methods inherited from Null
#Optional options (unused).=, #append, #buffered, #indent, #indented, #outdent, #puts, #write
Methods included from Messages
#assert, #error, #error_prefix, #fail_prefix, #inform_prefix, #pass_prefix, #skip_prefix
Constructor Details
#initialize(io, identity = nil) ⇒ Structured
Initialize a new Structured output handler.
23 24 25 26 |
# File 'lib/sus/output/structured.rb', line 23 def initialize(io, identity = nil) @io = io @identity = identity end |
Class Method Details
Instance Method Details
#inform(message, identity) ⇒ Object
Output an informational message as JSON.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sus/output/structured.rb', line 38 def inform(, identity) unless .is_a?(String) = .inspect end @io.puts(JSON.generate({ inform: @identity, message: { text: , location: identity&.to_location, } })) @io.flush end |
#skip(reason, identity) ⇒ Object
Output a skip message as JSON.
31 32 33 |
# File 'lib/sus/output/structured.rb', line 31 def skip(reason, identity) inform(reason.to_s, identity) end |