class SiteHealth::Issue

Represents a found issue inspired by the JSONAPI error spec

Constants

PRIORITIES
SEVERITIES

Attributes

code[RW]
detail[R]
meta[RW]
name[RW]
priority[R]
severity[R]
title[R]
url[RW]

Public Class Methods

fields() click to toggle source
# File lib/site_health/issue.rb, line 61
def self.fields
  %i[name code title detail severity priority url links meta]
end
new( name:, title:, code: nil, detail: '', severity: :unknown, priority: :unknown, url: nil, links: [], meta: {} ) click to toggle source

Initialize an Issue @param [String, Symbol] code an application-specific error code. @param [String] title a short, human-readable summary of the problem. @param [String] detail

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

@param [Array<Link>]

# 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

Public Instance Methods

detail=(detail) click to toggle source

Set issue detail. @param [String] detail

# File lib/site_health/issue.rb, line 80
def detail=(detail)
  @detail = detail.to_s
end
priority=(priority) click to toggle source

Set issue priority. @param [String, Symbol] priority @raise [ArgumentError] if priority is unknown

# File lib/site_health/issue.rb, line 100
def priority=(priority)
  priority = priority.to_sym

  unless PRIORITIES.include?(priority)
    priorities = PRIORITIES.to_a.join(', ')
    raise ArgumentError, "unknown value: '#{priority}', chose one of #{priorities}."
  end

  @priority = priority
end
severity=(severity) click to toggle source

Set issue severity. @param [String, Symbol] severity @raise [ArgumentError] if severity is unknown

# File lib/site_health/issue.rb, line 114
def severity=(severity)
  severity = severity.to_sym

  unless SEVERITIES.include?(severity)
    severities = SEVERITIES.to_a.join(', ')
    raise ArgumentError, "unknown value: '#{severity}', chose one of #{severities}."
  end

  @severity = severity
end
title=(title) click to toggle source

Set issue title. @param [String] title

# File lib/site_health/issue.rb, line 74
def title=(title)
  @title = title.to_s
end
to_h() click to toggle source

@return [Hash] hash representation of the object

# File lib/site_health/issue.rb, line 66
def to_h
  self.class.fields.
    map { |field| [field, send(field)] }.
    to_h
end