Class: Sarif::Exception
- Inherits:
-
Object
- Object
- Sarif::Exception
- Defined in:
- lib/sarif/exception.rb
Overview
Describes a runtime exception encountered during the execution of an analysis tool.
Instance Attribute Summary collapse
-
#inner_exceptions ⇒ Object
Returns the value of attribute inner_exceptions.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#message ⇒ Object
Returns the value of attribute message.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#stack ⇒ Object
Returns the value of attribute stack.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(kind: nil, message: nil, stack: nil, inner_exceptions: [], properties: nil) ⇒ Exception
constructor
A new instance of Exception.
- #to_h ⇒ Object
- #to_json(pretty: false) ⇒ Object
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 = @stack = stack @inner_exceptions = inner_exceptions @properties = properties end |
Instance Attribute Details
#inner_exceptions ⇒ Object
Returns the value of attribute inner_exceptions.
6 7 8 |
# File 'lib/sarif/exception.rb', line 6 def inner_exceptions @inner_exceptions end |
#kind ⇒ Object
Returns the value of attribute kind.
6 7 8 |
# File 'lib/sarif/exception.rb', line 6 def kind @kind end |
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/sarif/exception.rb', line 6 def @message end |
#properties ⇒ Object
Returns the value of attribute properties.
6 7 8 |
# File 'lib/sarif/exception.rb', line 6 def properties @properties end |
#stack ⇒ Object
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. && @stack == other.stack && @inner_exceptions == other.inner_exceptions && @properties == other.properties end |
#hash ⇒ Object
48 49 50 |
# File 'lib/sarif/exception.rb', line 48 def hash [@kind, @message, @stack, @inner_exceptions, @properties].hash end |
#to_h ⇒ Object
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 |