Class: HeapScope::Finding

Inherits:
Object
  • Object
show all
Defined in:
lib/heapscope/findings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, severity:, title: nil, facts: [], derived: [], hypothesis: nil, suspected_cause: nil, evidence: [], suggestions: [], subject: nil) ⇒ Finding

Returns a new instance of Finding.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/heapscope/findings.rb', line 108

def initialize(code:, severity:, title: nil, facts: [], derived: [],
               hypothesis: nil, suspected_cause: nil, evidence: [],
               suggestions: [], subject: nil)
  meta = Diagnostics::CODES[code] || {}
  @code = code
  @severity = severity || meta[:default_severity] || :low
  @title = title || meta[:title] || code
  @facts = Array(facts)
  @derived = Array(derived)
  @hypothesis = hypothesis
  @suspected_cause = suspected_cause
  @evidence = Array(evidence)
  @suggestions = Array(suggestions)
  @subject = subject
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def code
  @code
end

#derivedObject (readonly)

Returns the value of attribute derived.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def derived
  @derived
end

#evidenceObject (readonly)

Returns the value of attribute evidence.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def evidence
  @evidence
end

#factsObject (readonly)

Returns the value of attribute facts.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def facts
  @facts
end

#hypothesisObject (readonly)

Returns the value of attribute hypothesis.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def hypothesis
  @hypothesis
end

#severityObject (readonly)

Returns the value of attribute severity.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def severity
  @severity
end

#subjectObject (readonly)

Returns the value of attribute subject.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def subject
  @subject
end

#suggestionsObject (readonly)

Returns the value of attribute suggestions.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def suggestions
  @suggestions
end

#suspected_causeObject (readonly)

Returns the value of attribute suspected_cause.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def suspected_cause
  @suspected_cause
end

#titleObject (readonly)

Returns the value of attribute title.



105
106
107
# File 'lib/heapscope/findings.rb', line 105

def title
  @title
end

Instance Method Details

#nameObject



124
125
126
# File 'lib/heapscope/findings.rb', line 124

def name
  Diagnostics::CODES.dig(code, :name)
end

#priorityObject



128
129
130
# File 'lib/heapscope/findings.rb', line 128

def priority
  Findings.priority_score(self)
end

#to_hObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/heapscope/findings.rb', line 132

def to_h
  {
    code: code,
    name: name,
    severity: severity.to_s,
    title: title,
    subject: subject,
    priority: priority,
    facts: facts,
    derived: derived,
    hypothesis: hypothesis,
    suspected_cause: suspected_cause,
    evidence: evidence,
    suggestions: suggestions
  }.compact
end