Class: Lutaml::Xsd::Validation::ResultCollector
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Validation::ResultCollector
- Defined in:
- lib/lutaml/xsd/validation/result_collector.rb
Overview
ResultCollector aggregates validation results
This class collects validation errors, warnings, and info messages during the validation process and provides methods to aggregate them into a final ValidationResult.
Defined Under Namespace
Classes: StopValidationError
Instance Attribute Summary collapse
-
#config ⇒ ValidationConfiguration
readonly
The validation configuration.
-
#errors ⇒ Array<ValidationError>
readonly
Collection of errors.
-
#infos ⇒ Array<ValidationError>
readonly
Collection of info messages.
-
#warnings ⇒ Array<ValidationError>
readonly
Collection of warnings.
Instance Method Summary collapse
-
#add_error(error) ⇒ void
Add an error to the collection.
-
#add_info(info) ⇒ void
Add an info message to the collection.
-
#add_issue(issue) ⇒ void
Add an issue based on its severity.
-
#add_warning(warning) ⇒ void
Add a warning to the collection.
-
#all_issues ⇒ Array<ValidationError>
Get all issues (errors + warnings + infos).
-
#clear ⇒ void
Clear all collected results.
-
#count_by_severity ⇒ Hash<Symbol, Integer>
Get count by severity.
-
#has_errors? ⇒ Boolean
Check if there are any errors.
-
#has_infos? ⇒ Boolean
Check if there are any info messages.
-
#has_issues? ⇒ Boolean
Check if there are any issues at all.
-
#has_warnings? ⇒ Boolean
Check if there are any warnings.
-
#initialize(config) ⇒ ResultCollector
constructor
Initialize a new ResultCollector.
-
#issues_at_location(location) ⇒ Array<ValidationError>
Filter issues by location.
-
#issues_with_code(code) ⇒ Array<ValidationError>
Filter issues by code.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#to_result ⇒ ValidationResult
Convert collected results to a ValidationResult.
-
#total_count ⇒ Integer
Get total count of all issues.
Constructor Details
#initialize(config) ⇒ ResultCollector
Initialize a new ResultCollector
36 37 38 39 40 41 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 36 def initialize(config) @config = config @errors = [] @warnings = [] @infos = [] end |
Instance Attribute Details
#config ⇒ ValidationConfiguration (readonly)
Returns The validation configuration.
22 23 24 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 22 def config @config end |
#errors ⇒ Array<ValidationError> (readonly)
Returns Collection of errors.
25 26 27 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 25 def errors @errors end |
#infos ⇒ Array<ValidationError> (readonly)
Returns Collection of info messages.
31 32 33 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 31 def infos @infos end |
#warnings ⇒ Array<ValidationError> (readonly)
Returns Collection of warnings.
28 29 30 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 28 def warnings @warnings end |
Instance Method Details
#add_error(error) ⇒ void
This method returns an undefined value.
Add an error to the collection
49 50 51 52 53 54 55 56 57 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 49 def add_error(error) validate_error!(error) return if should_skip_error?(error) @errors << error # Stop collecting if configured to stop on first error raise StopValidationError if stop_on_first_error? && has_errors? end |
#add_info(info) ⇒ void
This method returns an undefined value.
Add an info message to the collection
78 79 80 81 82 83 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 78 def add_info(info) validate_error!(info) return if should_skip_error?(info) @infos << info end |
#add_issue(issue) ⇒ void
This method returns an undefined value.
Add an issue based on its severity
Automatically routes the issue to the appropriate collection based on its severity level.
92 93 94 95 96 97 98 99 100 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 92 def add_issue(issue) case issue.severity when :error then add_error(issue) when :warning then add_warning(issue) when :info then add_info(issue) else raise ArgumentError, "Invalid severity: #{issue.severity}" end end |
#add_warning(warning) ⇒ void
This method returns an undefined value.
Add a warning to the collection
65 66 67 68 69 70 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 65 def add_warning(warning) validate_error!(warning) return if should_skip_error?(warning) @warnings << warning end |
#all_issues ⇒ Array<ValidationError>
Get all issues (errors + warnings + infos)
172 173 174 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 172 def all_issues @errors + @warnings + @infos end |
#clear ⇒ void
This method returns an undefined value.
Clear all collected results
163 164 165 166 167 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 163 def clear @errors.clear @warnings.clear @infos.clear end |
#count_by_severity ⇒ Hash<Symbol, Integer>
Get count by severity
140 141 142 143 144 145 146 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 140 def count_by_severity { errors: @errors.size, warnings: @warnings.size, infos: @infos.size, } end |
#has_errors? ⇒ Boolean
Check if there are any errors
105 106 107 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 105 def has_errors? @errors.any? end |
#has_infos? ⇒ Boolean
Check if there are any info messages
119 120 121 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 119 def has_infos? @infos.any? end |
#has_issues? ⇒ Boolean
Check if there are any issues at all
126 127 128 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 126 def has_issues? has_errors? || has_warnings? || has_infos? end |
#has_warnings? ⇒ Boolean
Check if there are any warnings
112 113 114 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 112 def has_warnings? @warnings.any? end |
#issues_at_location(location) ⇒ Array<ValidationError>
Filter issues by location
188 189 190 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 188 def issues_at_location(location) all_issues.select { |issue| issue.location == location } end |
#issues_with_code(code) ⇒ Array<ValidationError>
Filter issues by code
180 181 182 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 180 def issues_with_code(code) all_issues.select { |issue| issue.code == code } end |
#to_h ⇒ Hash
Convert to hash representation
195 196 197 198 199 200 201 202 203 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 195 def to_h { errors: @errors.map(&:to_h), warnings: @warnings.map(&:to_h), infos: @infos.map(&:to_h), counts: count_by_severity, valid: !has_errors?, } end |
#to_result ⇒ ValidationResult
Convert collected results to a ValidationResult
151 152 153 154 155 156 157 158 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 151 def to_result ValidationResult.new( valid: !has_errors?, errors: @errors.dup, warnings: @warnings.dup, infos: @infos.dup, ) end |
#total_count ⇒ Integer
Get total count of all issues
133 134 135 |
# File 'lib/lutaml/xsd/validation/result_collector.rb', line 133 def total_count @errors.size + @warnings.size + @infos.size end |