Class: Yard::Lint::Results::Aggregate
- Inherits:
-
Object
- Object
- Yard::Lint::Results::Aggregate
- Defined in:
- lib/yard/lint/results/aggregate.rb
Overview
Aggregates multiple validator results into a single result object
Constant Summary collapse
- SEVERITY_ERROR =
Error severity level constant
'error'- SEVERITY_WARNING =
Warning severity level constant
'warning'- SEVERITY_CONVENTION =
Convention severity level constant
'convention'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#clean? ⇒ Boolean
Check if there are no offenses.
-
#count ⇒ Integer
Total number of offenses.
-
#exit_code ⇒ Integer
Determine exit code based on configured fail_on_severity Uses the config object stored during initialization.
-
#initialize(results, config = nil) ⇒ Aggregate
constructor
Initialize aggregate result with array of validator results.
-
#offenses ⇒ Array<Hash>
Get all offenses from all validators.
-
#statistics ⇒ Hash
Get offense statistics by severity.
Constructor Details
#initialize(results, config = nil) ⇒ Aggregate
Initialize aggregate result with array of validator results
21 22 23 24 |
# File 'lib/yard/lint/results/aggregate.rb', line 21 def initialize(results, config = nil) @results = Array(results) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/yard/lint/results/aggregate.rb', line 16 def config @config end |
Instance Method Details
#clean? ⇒ Boolean
Check if there are no offenses
40 41 42 |
# File 'lib/yard/lint/results/aggregate.rb', line 40 def clean? offenses.empty? end |
#count ⇒ Integer
Total number of offenses
34 35 36 |
# File 'lib/yard/lint/results/aggregate.rb', line 34 def count offenses.count end |
#exit_code ⇒ Integer
Determine exit code based on configured fail_on_severity Uses the config object stored during initialization
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/yard/lint/results/aggregate.rb', line 66 def exit_code return 0 if offenses.empty? return 0 unless @config # No config means don't fail fail_on = @config.fail_on_severity case fail_on when SEVERITY_ERROR statistics[:error].positive? ? 1 : 0 when SEVERITY_WARNING (statistics[:error] + statistics[:warning]).positive? ? 1 : 0 when SEVERITY_CONVENTION offenses.any? ? 1 : 0 else 0 end end |
#offenses ⇒ Array<Hash>
Get all offenses from all validators
28 29 30 |
# File 'lib/yard/lint/results/aggregate.rb', line 28 def offenses @results.flat_map(&:offenses) end |
#statistics ⇒ Hash
Get offense statistics by severity
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/yard/lint/results/aggregate.rb', line 46 def statistics stats = { error: 0, warning: 0, convention: 0, total: 0 } offenses.each do |offense| severity = offense[:severity].to_sym stats[severity] += 1 if stats.key?(severity) stats[:total] += 1 end stats end |