Class: RedQuilt::Diagnostic
- Inherits:
-
Object
- Object
- RedQuilt::Diagnostic
- Defined in:
- lib/red_quilt/diagnostic.rb
Overview
A single warning / error raised while parsing or rendering a document. Diagnostics are collected on the Document and never interrupt processing — every parse / render call still produces a tree and HTML, even if it emitted diagnostics along the way.
severity: :info / :warning / :error rule: a short Symbol identifying the rule (e.g. :unsafe_url,
:missing_reference) so callers can filter / silence
message: human-readable explanation source_span: optional SourceSpan, points at the offending byte range
Constant Summary collapse
- SEVERITIES =
%i[info warning error].freeze
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#source_span ⇒ Object
readonly
Returns the value of attribute source_span.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(severity:, rule:, message:, source_span: nil) ⇒ Diagnostic
constructor
A new instance of Diagnostic.
- #to_h ⇒ Object
Constructor Details
#initialize(severity:, rule:, message:, source_span: nil) ⇒ Diagnostic
Returns a new instance of Diagnostic.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/red_quilt/diagnostic.rb', line 19 def initialize(severity:, rule:, message:, source_span: nil) unless SEVERITIES.include?(severity) raise ArgumentError, "unknown severity: #{severity.inspect}" end @severity = severity @rule = rule @message = @source_span = source_span end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
17 18 19 |
# File 'lib/red_quilt/diagnostic.rb', line 17 def @message end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
17 18 19 |
# File 'lib/red_quilt/diagnostic.rb', line 17 def rule @rule end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
17 18 19 |
# File 'lib/red_quilt/diagnostic.rb', line 17 def severity @severity end |
#source_span ⇒ Object (readonly)
Returns the value of attribute source_span.
17 18 19 |
# File 'lib/red_quilt/diagnostic.rb', line 17 def source_span @source_span end |
Instance Method Details
#==(other) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/red_quilt/diagnostic.rb', line 39 def ==(other) other.is_a?(Diagnostic) && other.severity == severity && other.rule == rule && other. == && other.source_span == source_span end |
#to_h ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/red_quilt/diagnostic.rb', line 30 def to_h { severity: severity, rule: rule, message: , source_span: source_span && { start_byte: source_span.start_byte, end_byte: source_span.end_byte }, } end |