Class: ArchSpec::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/archspec/diagnostic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule:, message:, location:, evidence:, confidence: :high) ⇒ Diagnostic

Returns a new instance of Diagnostic.



7
8
9
10
11
12
13
# File 'lib/archspec/diagnostic.rb', line 7

def initialize(rule:, message:, location:, evidence:, confidence: :high)
  @rule = rule
  @message = message
  @location = location
  @evidence = evidence
  @confidence = confidence
end

Instance Attribute Details

#confidenceObject (readonly)

Returns the value of attribute confidence.



5
6
7
# File 'lib/archspec/diagnostic.rb', line 5

def confidence
  @confidence
end

#evidenceObject (readonly)

Returns the value of attribute evidence.



5
6
7
# File 'lib/archspec/diagnostic.rb', line 5

def evidence
  @evidence
end

#locationObject (readonly)

Returns the value of attribute location.



5
6
7
# File 'lib/archspec/diagnostic.rb', line 5

def location
  @location
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/archspec/diagnostic.rb', line 5

def message
  @message
end

#ruleObject (readonly)

Returns the value of attribute rule.



5
6
7
# File 'lib/archspec/diagnostic.rb', line 5

def rule
  @rule
end

Instance Method Details

#fingerprint(root: nil) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/archspec/diagnostic.rb', line 15

def fingerprint(root: nil)
  path = root ? location.relative_path(root) : location.path

  Digest::SHA256.hexdigest(
    [rule, message, path, location.line, evidence].join("\0")
  )[0, 24]
end

#to_h(root:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/archspec/diagnostic.rb', line 23

def to_h(root:)
  {
    id: fingerprint(root: root),
    rule: rule,
    message: message,
    path: location.relative_path(root),
    line: location.line,
    column: location.column,
    evidence: evidence,
    confidence: confidence.to_s
  }
end