Class: Reviewer::Report
- Inherits:
-
Object
- Object
- Reviewer::Report
- Defined in:
- lib/reviewer/report.rb,
lib/reviewer/report/formatter.rb
Overview
Collects results from multiple tool runs and provides serialization
Defined Under Namespace
Classes: Formatter
Constant Summary collapse
- SCHEMA_VERSION =
1
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Class Method Summary collapse
-
.empty(message: 'No tools ran') ⇒ Hash
Builds an empty report envelope with a context-specific message.
-
.empty_summary ⇒ Hash
Builds the zero-valued summary shared by empty and error envelopes.
Instance Method Summary collapse
-
#add(result) ⇒ Array<Runner::Result>
Adds a Runner::Result to the collection.
-
#exit_code ⇒ Integer
The process exit code, derived from the verdict rather than from whatever a tool returned.
-
#initialize ⇒ Report
constructor
A new instance of Report.
-
#missing? ⇒ Boolean
Whether any tools were missing.
-
#missing_results ⇒ Array<Runner::Result>
Returns results for tools whose executables were not found.
-
#missing_tools ⇒ Array<Runner::Result>
Returns data for missing tools (name and key).
-
#record_duration(seconds) ⇒ Float
Records the total duration for all tool runs.
-
#success? ⇒ Boolean
Whether all executed tools in the report succeeded.
-
#summary ⇒ Hash
Counts each result by its explicit state.
-
#to_h(empty_message: 'No tools ran') ⇒ Hash
Converts the report to a hash suitable for serialization.
-
#to_json(*_args) ⇒ String
Converts the report to formatted JSON.
Constructor Details
#initialize ⇒ Report
Returns a new instance of Report.
41 42 43 44 |
# File 'lib/reviewer/report.rb', line 41 def initialize @results = [] @duration = nil end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
39 40 41 |
# File 'lib/reviewer/report.rb', line 39 def duration @duration end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
39 40 41 |
# File 'lib/reviewer/report.rb', line 39 def results @results end |
Class Method Details
.empty(message: 'No tools ran') ⇒ Hash
Builds an empty report envelope with a context-specific message.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/reviewer/report.rb', line 28 def self.empty(message: 'No tools ran') { schema_version: SCHEMA_VERSION, state: 'empty', success: true, message: , summary: empty_summary, tools: [] } end |
.empty_summary ⇒ Hash
Builds the zero-valued summary shared by empty and error envelopes.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/reviewer/report.rb', line 13 def self.empty_summary { total: 0, passed: 0, failed: 0, skipped: 0, missing: 0, not_run: 0, duration: 0 } end |
Instance Method Details
#add(result) ⇒ Array<Runner::Result>
Adds a Runner::Result to the collection
50 51 52 |
# File 'lib/reviewer/report.rb', line 50 def add(result) @results << result end |
#exit_code ⇒ Integer
The process exit code, derived from the verdict rather than from whatever a
tool returned. Forwarding a tool's status meant a tool passing under its
max_exit_status still exited non-zero, and a tool exiting 2 -- GNU ls
does, on an unknown option -- was indistinguishable from the usage errors
Session::USAGE_ERROR reports.
76 |
# File 'lib/reviewer/report.rb', line 76 def exit_code = success? ? 0 : 1 |
#missing? ⇒ Boolean
Whether any tools were missing
88 89 90 |
# File 'lib/reviewer/report.rb', line 88 def missing? missing_results.any? end |
#missing_results ⇒ Array<Runner::Result>
Returns results for tools whose executables were not found
81 82 83 |
# File 'lib/reviewer/report.rb', line 81 def missing_results results.select(&:missing?) end |
#missing_tools ⇒ Array<Runner::Result>
Returns data for missing tools (name and key)
95 96 97 |
# File 'lib/reviewer/report.rb', line 95 def missing_tools missing_results end |
#record_duration(seconds) ⇒ Float
Records the total duration for all tool runs
58 59 60 |
# File 'lib/reviewer/report.rb', line 58 def record_duration(seconds) @duration = seconds end |
#success? ⇒ Boolean
Whether all executed tools in the report succeeded
65 66 67 |
# File 'lib/reviewer/report.rb', line 65 def success? executed_results.all?(&:success?) end |
#summary ⇒ Hash
Counts each result by its explicit state.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/reviewer/report.rb', line 101 def summary { total: results.size, passed: results.count(&:passed?), failed: results.count(&:failed?), skipped: results.count(&:skipped?), missing: results.count(&:missing?), not_run: results.count(&:not_run?), duration: duration } end |
#to_h(empty_message: 'No tools ran') ⇒ Hash
Converts the report to a hash suitable for serialization
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/reviewer/report.rb', line 117 def to_h(empty_message: 'No tools ran') return self.class.empty(message: ) if results.empty? { schema_version: SCHEMA_VERSION, success: success?, summary: summary, tools: results.map(&:to_h) } end |
#to_json(*_args) ⇒ String
Converts the report to formatted JSON
131 132 133 |
# File 'lib/reviewer/report.rb', line 131 def to_json(*_args) JSON.pretty_generate(to_h) end |