Class: Sarif::StackFrame

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

Overview

A function call within a stack trace.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location: nil, module_name: nil, thread_id: nil, parameters: [], properties: nil) ⇒ StackFrame



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

def initialize(location: nil, module_name: nil, thread_id: nil, parameters: [], properties: nil)
  @location = location
  @module_name = module_name
  @thread_id = thread_id
  @parameters = parameters
  @properties = properties
end

Instance Attribute Details

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#module_nameObject

Returns the value of attribute module_name.



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

def module_name
  @module_name
end

#parametersObject

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#thread_idObject

Returns the value of attribute thread_id.



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

def thread_id
  @thread_id
end

Class Method Details

.from_hash(h) ⇒ Object



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

def self.from_hash(h)
  return nil if h.nil?
  new(
    location: Location.from_hash(h["location"]),
    module_name: h["module"],
    thread_id: h["threadId"],
    parameters: h["parameters"] || [],
    properties: h["properties"]
  )
end

Instance Method Details

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



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

def ==(other)
  return false unless other.is_a?(StackFrame)
  @location == other.location && @module_name == other.module_name && @thread_id == other.thread_id && @parameters == other.parameters && @properties == other.properties
end

#hashObject



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

def hash
  [@location, @module_name, @thread_id, @parameters, @properties].hash
end

#to_hObject



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

def to_h
  h = {}
  h["location"] = @location&.to_h unless @location.nil?
  h["module"] = @module_name unless @module_name.nil?
  h["threadId"] = @thread_id unless @thread_id.nil?
  h["parameters"] = @parameters if @parameters&.any?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



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

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