Class: SvgConform::Validation::ErrorTracker
- Inherits:
-
Object
- Object
- SvgConform::Validation::ErrorTracker
- Defined in:
- lib/svg_conform/validation/error_tracker.rb
Overview
Tracks validation errors, warnings, and informational messages Separated from ValidationContext for better separation of concerns
Note: This class references ValidationContext::ValidationIssue which is defined in ValidationContext. ValidationContext must be loaded first.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#infos ⇒ Object
readonly
Returns the value of attribute infos.
-
#validity_errors ⇒ Object
readonly
Returns the value of attribute validity_errors.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#add_error(node:, message:, rule: nil, requirement: nil, requirement_id: nil, severity: nil, fix: nil, data: {}) ⇒ Object
Add an error to the context.
-
#add_notice(rule:, node:, message:, fix: nil, data: {}, type: :info) ⇒ Object
Add an informational notice to the context.
-
#add_warning(rule:, node:, message:, fix: nil) ⇒ Object
Add a warning to the context.
-
#clear ⇒ Object
Clear all tracked issues.
-
#has_errors? ⇒ Boolean
Check if there are any errors.
-
#has_validity_errors? ⇒ Boolean
Check if there are any validity errors.
-
#has_warnings? ⇒ Boolean
Check if there are any warnings.
-
#initialize ⇒ ErrorTracker
constructor
A new instance of ErrorTracker.
-
#total_error_count ⇒ Object
Get total error count (including validity errors).
Constructor Details
#initialize ⇒ ErrorTracker
Returns a new instance of ErrorTracker.
13 14 15 16 17 18 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 13 def initialize @errors = [] @warnings = [] @validity_errors = [] @infos = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
11 12 13 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 11 def errors @errors end |
#infos ⇒ Object (readonly)
Returns the value of attribute infos.
11 12 13 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 11 def infos @infos end |
#validity_errors ⇒ Object (readonly)
Returns the value of attribute validity_errors.
11 12 13 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 11 def validity_errors @validity_errors end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
11 12 13 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 11 def warnings @warnings end |
Instance Method Details
#add_error(node:, message:, rule: nil, requirement: nil, requirement_id: nil, severity: nil, fix: nil, data: {}) ⇒ Object
Add an error to the context
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 21 def add_error(node:, message:, rule: nil, requirement: nil, requirement_id: nil, severity: nil, fix: nil, data: {}) # Support both old rule system and new requirements system rule_or_requirement = requirement || rule error = ::SvgConform::Errors::ValidationIssue.new( type: :error, rule: rule_or_requirement, node: node, message: , fix: fix, data: data, requirement_id: requirement_id, severity: severity, ) # Handle special severity types if severity == :validity_error @validity_errors << error else @errors << error end error end |
#add_notice(rule:, node:, message:, fix: nil, data: {}, type: :info) ⇒ Object
Add an informational notice to the context
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 61 def add_notice(rule:, node:, message:, fix: nil, data: {}, type: :info) notice = ::SvgConform::Errors::ValidationIssue.new( type: type, rule: rule, node: node, message: , fix: fix, data: data, ) @infos << notice notice end |
#add_warning(rule:, node:, message:, fix: nil) ⇒ Object
Add a warning to the context
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 48 def add_warning(rule:, node:, message:, fix: nil) warning = ::SvgConform::Errors::ValidationIssue.new( type: :warning, rule: rule, node: node, message: , fix: fix, ) @warnings << warning warning end |
#clear ⇒ Object
Clear all tracked issues
95 96 97 98 99 100 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 95 def clear @errors.clear @warnings.clear @validity_errors.clear @infos.clear end |
#has_errors? ⇒ Boolean
Check if there are any errors
75 76 77 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 75 def has_errors? @errors.any? end |
#has_validity_errors? ⇒ Boolean
Check if there are any validity errors
85 86 87 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 85 def has_validity_errors? @validity_errors.any? end |
#has_warnings? ⇒ Boolean
Check if there are any warnings
80 81 82 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 80 def has_warnings? @warnings.any? end |
#total_error_count ⇒ Object
Get total error count (including validity errors)
90 91 92 |
# File 'lib/svg_conform/validation/error_tracker.rb', line 90 def total_error_count @errors.length + @validity_errors.length end |