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
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#add(result) ⇒ Array<Runner::Result>
Adds a Runner::Result to the collection.
-
#initialize ⇒ Report
constructor
A new instance of Report.
-
#max_exit_status ⇒ Integer
Returns the highest exit status from executed results (excludes missing and skipped).
-
#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 (excludes missing and skipped).
-
#to_h ⇒ 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.
11 12 13 14 |
# File 'lib/reviewer/report.rb', line 11 def initialize @results = [] @duration = nil end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
9 10 11 |
# File 'lib/reviewer/report.rb', line 9 def duration @duration end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
9 10 11 |
# File 'lib/reviewer/report.rb', line 9 def results @results end |
Instance Method Details
#add(result) ⇒ Array<Runner::Result>
Adds a Runner::Result to the collection
20 21 22 |
# File 'lib/reviewer/report.rb', line 20 def add(result) @results << result end |
#max_exit_status ⇒ Integer
Returns the highest exit status from executed results (excludes missing and skipped)
42 43 44 |
# File 'lib/reviewer/report.rb', line 42 def max_exit_status executed_results.map(&:exit_status).max || 0 end |
#missing? ⇒ Boolean
Whether any tools were missing
56 57 58 |
# File 'lib/reviewer/report.rb', line 56 def missing? missing_results.any? end |
#missing_results ⇒ Array<Runner::Result>
Returns results for tools whose executables were not found
49 50 51 |
# File 'lib/reviewer/report.rb', line 49 def missing_results results.select(&:missing?) end |
#missing_tools ⇒ Array<Runner::Result>
Returns data for missing tools (name and key)
63 64 65 |
# File 'lib/reviewer/report.rb', line 63 def missing_tools missing_results end |
#record_duration(seconds) ⇒ Float
Records the total duration for all tool runs
28 29 30 |
# File 'lib/reviewer/report.rb', line 28 def record_duration(seconds) @duration = seconds end |
#success? ⇒ Boolean
Whether all executed tools in the report succeeded (excludes missing and skipped)
35 36 37 |
# File 'lib/reviewer/report.rb', line 35 def success? executed_results.all?(&:success?) end |
#to_h ⇒ Hash
Converts the report to a hash suitable for serialization
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/reviewer/report.rb', line 70 def to_h { success: success?, summary: { total: results.size, passed: results.count(&:success?), failed: results.count { |result| !result.success? && !result.missing? }, missing: missing_results.size, duration: duration }, tools: results.map(&:to_h) } end |
#to_json(*_args) ⇒ String
Converts the report to formatted JSON
87 88 89 |
# File 'lib/reviewer/report.rb', line 87 def to_json(*_args) JSON.pretty_generate(to_h) end |