Class: SiteHealth::Issue

Inherits:
Object
  • Object
show all
Defined in:
lib/site_health/issue.rb

Overview

Represents a found issue inspired by the JSONAPI error spec

Constant Summary collapse

PRIORITIES =
Set.new(
  %i[
    critial
    high
    medium
    low
    fyi
    unknown
  ].freeze
)
SEVERITIES =
Set.new(
  %i[
    critial
    major
    medium
    low
    fyi
    unknown
  ].freeze
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, title:, code: nil, detail: '', severity: :unknown, priority: :unknown, url: nil, links: [], meta: {}) ⇒ Issue

Initialize an Issue

Parameters:

  • code (String, Symbol) (defaults to: nil)

    an application-specific error code.

  • title (String)

    a short, human-readable summary of the problem.

  • detail (String) (defaults to: '')

    a human-readable explanation specific to this occurrence of the problem.

  • (Array<Link>)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/site_health/issue.rb', line 39

def initialize(
  name:,
  title:,
  code: nil,
  detail: '',
  severity: :unknown,
  priority: :unknown,
  url: nil,
  links: [],
  meta: {}
)
  self.name = name
  self.code = code
  self.url = url
  self.meta = meta
  self.title = title
  self.detail = detail
  self.links = links
  self.severity = severity
  self.priority = priority
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



30
31
32
# File 'lib/site_health/issue.rb', line 30

def code
  @code
end

#detailObject

Returns the value of attribute detail.



31
32
33
# File 'lib/site_health/issue.rb', line 31

def detail
  @detail
end

Returns the value of attribute links.



31
32
33
# File 'lib/site_health/issue.rb', line 31

def links
  @links
end

#metaObject

Returns the value of attribute meta.



30
31
32
# File 'lib/site_health/issue.rb', line 30

def meta
  @meta
end

#nameObject

Returns the value of attribute name.



30
31
32
# File 'lib/site_health/issue.rb', line 30

def name
  @name
end

#priorityObject

Returns the value of attribute priority.



31
32
33
# File 'lib/site_health/issue.rb', line 31

def priority
  @priority
end

#severityObject

Returns the value of attribute severity.



31
32
33
# File 'lib/site_health/issue.rb', line 31

def severity
  @severity
end

#titleObject

Returns the value of attribute title.



31
32
33
# File 'lib/site_health/issue.rb', line 31

def title
  @title
end

#urlObject

Returns the value of attribute url.



30
31
32
# File 'lib/site_health/issue.rb', line 30

def url
  @url
end

Class Method Details

.fieldsObject



61
62
63
# File 'lib/site_health/issue.rb', line 61

def self.fields
  %i[name code title detail severity priority url links meta]
end

Instance Method Details

#to_hHash

Returns hash representation of the object.

Returns:

  • (Hash)

    hash representation of the object



66
67
68
69
70
# File 'lib/site_health/issue.rb', line 66

def to_h
  self.class.fields.
    map { |field| [field, send(field)] }.
    to_h
end