Class: Sarif::Stack

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

Overview

A call stack that is relevant to a result.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message: nil, frames:, properties: nil) ⇒ Stack

Returns a new instance of Stack.



8
9
10
11
12
# File 'lib/sarif/stack.rb', line 8

def initialize(message: nil, frames:, properties: nil)
  @message = message
  @frames = frames
  @properties = properties
end

Instance Attribute Details

#framesObject

Returns the value of attribute frames.



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

def frames
  @frames
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

Class Method Details

.from_hash(h) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/sarif/stack.rb', line 26

def self.from_hash(h)
  return nil if h.nil?
  new(
    message: Message.from_hash(h["message"]),
    frames: h["frames"]&.map { |v| StackFrame.from_hash(v) },
    properties: h["properties"]
  )
end

Instance Method Details

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



35
36
37
38
# File 'lib/sarif/stack.rb', line 35

def ==(other)
  return false unless other.is_a?(Stack)
  @message == other.message && @frames == other.frames && @properties == other.properties
end

#hashObject



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

def hash
  [@message, @frames, @properties].hash
end

#to_hObject



14
15
16
17
18
19
20
# File 'lib/sarif/stack.rb', line 14

def to_h
  h = {}
  h["message"] = @message&.to_h unless @message.nil?
  h["frames"] = @frames&.map(&:to_h)
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



22
23
24
# File 'lib/sarif/stack.rb', line 22

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