Class: Sarif::Exception

Inherits:
Object
  • Object
show all
Defined in:
lib/sarif/exception.rb

Overview

Describes a runtime exception encountered during the execution of an analysis tool.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind: nil, message: nil, stack: nil, inner_exceptions: [], properties: nil) ⇒ Exception

Returns a new instance of Exception.



8
9
10
11
12
13
14
# File 'lib/sarif/exception.rb', line 8

def initialize(kind: nil, message: nil, stack: nil, inner_exceptions: [], properties: nil)
  @kind = kind
  @message = message
  @stack = stack
  @inner_exceptions = inner_exceptions
  @properties = properties
end

Instance Attribute Details

#inner_exceptionsObject

Returns the value of attribute inner_exceptions.



6
7
8
# File 'lib/sarif/exception.rb', line 6

def inner_exceptions
  @inner_exceptions
end

#kindObject

Returns the value of attribute kind.



6
7
8
# File 'lib/sarif/exception.rb', line 6

def kind
  @kind
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/sarif/exception.rb', line 6

def message
  @message
end

#propertiesObject

Returns the value of attribute properties.



6
7
8
# File 'lib/sarif/exception.rb', line 6

def properties
  @properties
end

#stackObject

Returns the value of attribute stack.



6
7
8
# File 'lib/sarif/exception.rb', line 6

def stack
  @stack
end

Class Method Details

.from_hash(h) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/sarif/exception.rb', line 30

def self.from_hash(h)
  return nil if h.nil?
  new(
    kind: h["kind"],
    message: h["message"],
    stack: Stack.from_hash(h["stack"]),
    inner_exceptions: h["innerExceptions"]&.map { |v| Exception.from_hash(v) } || [],
    properties: h["properties"]
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



41
42
43
44
# File 'lib/sarif/exception.rb', line 41

def ==(other)
  return false unless other.is_a?(Exception)
  @kind == other.kind && @message == other.message && @stack == other.stack && @inner_exceptions == other.inner_exceptions && @properties == other.properties
end

#hashObject



48
49
50
# File 'lib/sarif/exception.rb', line 48

def hash
  [@kind, @message, @stack, @inner_exceptions, @properties].hash
end

#to_hObject



16
17
18
19
20
21
22
23
24
# File 'lib/sarif/exception.rb', line 16

def to_h
  h = {}
  h["kind"] = @kind unless @kind.nil?
  h["message"] = @message unless @message.nil?
  h["stack"] = @stack&.to_h unless @stack.nil?
  h["innerExceptions"] = @inner_exceptions&.map(&:to_h) if @inner_exceptions&.any?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



26
27
28
# File 'lib/sarif/exception.rb', line 26

def to_json(pretty: false)
  pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h)
end