Class: Shojiku::Diagnostic

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

Overview

One thing the engine noticed about a document.

Passed through, never interpreted. code and args are the engine's frozen contract — a translating consumer renders its own message from them — so this class parses the wire and stops. It does not translate, it does not re-classify, and it never becomes an exception: a render that warns still succeeded, and a render that failed says why in these.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ Diagnostic

Returns a new instance of Diagnostic.



21
22
23
24
25
26
27
28
29
# File 'lib/shojiku/diagnostic.rb', line 21

def initialize(item)
  @severity = item["severity"]
  @code = item["code"]
  @category = item["category"]
  @message = item["message"]
  @path = item["path"]
  @args = item["args"] || {}
  @origin = item["origin"]
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



12
13
14
# File 'lib/shojiku/diagnostic.rb', line 12

def args
  @args
end

#categoryObject (readonly)

Returns the value of attribute category.



12
13
14
# File 'lib/shojiku/diagnostic.rb', line 12

def category
  @category
end

#codeObject (readonly)

Returns the value of attribute code.



12
13
14
# File 'lib/shojiku/diagnostic.rb', line 12

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



12
13
14
# File 'lib/shojiku/diagnostic.rb', line 12

def message
  @message
end

#originObject (readonly)

Returns the value of attribute origin.



12
13
14
# File 'lib/shojiku/diagnostic.rb', line 12

def origin
  @origin
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/shojiku/diagnostic.rb', line 12

def path
  @path
end

#severityObject (readonly)

Returns the value of attribute severity.



12
13
14
# File 'lib/shojiku/diagnostic.rb', line 12

def severity
  @severity
end

Class Method Details

.parse(json) ⇒ Object



14
15
16
17
18
19
# File 'lib/shojiku/diagnostic.rb', line 14

def self.parse(json)
  return [] if json.nil? || json.empty?

  items = JSON.parse(json)["items"]
  Array(items).map { |item| new(item) }
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/shojiku/diagnostic.rb', line 31

def error?
  @severity == "error"
end

#to_sObject



39
40
41
# File 'lib/shojiku/diagnostic.rb', line 39

def to_s
  [@path, @message].compact.join(": ")
end

#warning?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/shojiku/diagnostic.rb', line 35

def warning?
  @severity == "warning"
end