Class: Sarif::Notification

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

Overview

Describes a condition relevant to the tool itself, as opposed to being relevant to a target being analyzed by the tool.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locations: [], message:, level: "warning", thread_id: nil, time_utc: nil, exception: nil, descriptor: nil, associated_rule: nil, properties: nil) ⇒ Notification

Returns a new instance of Notification.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sarif/notification.rb', line 8

def initialize(locations: [], message:, level: "warning", thread_id: nil, time_utc: nil, exception: nil, descriptor: nil, associated_rule: nil, properties: nil)
  @locations = locations
  @message = message
  @level = level
  @thread_id = thread_id
  @time_utc = time_utc
  @exception = exception
  @descriptor = descriptor
  @associated_rule = associated_rule
  @properties = properties
end

Instance Attribute Details

#associated_ruleObject

Returns the value of attribute associated_rule.



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

def associated_rule
  @associated_rule
end

#descriptorObject

Returns the value of attribute descriptor.



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

def descriptor
  @descriptor
end

#exceptionObject

Returns the value of attribute exception.



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

def exception
  @exception
end

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

#locationsObject

Returns the value of attribute locations.



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

def locations
  @locations
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#thread_idObject

Returns the value of attribute thread_id.



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

def thread_id
  @thread_id
end

#time_utcObject

Returns the value of attribute time_utc.



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

def time_utc
  @time_utc
end

Class Method Details

.from_hash(h) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sarif/notification.rb', line 38

def self.from_hash(h)
  return nil if h.nil?
  new(
    locations: h["locations"]&.map { |v| Location.from_hash(v) } || [],
    message: Message.from_hash(h["message"]),
    level: h["level"] || "warning",
    thread_id: h["threadId"],
    time_utc: h["timeUtc"],
    exception: Exception.from_hash(h["exception"]),
    descriptor: ReportingDescriptorReference.from_hash(h["descriptor"]),
    associated_rule: ReportingDescriptorReference.from_hash(h["associatedRule"]),
    properties: h["properties"]
  )
end

Instance Method Details

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



53
54
55
56
# File 'lib/sarif/notification.rb', line 53

def ==(other)
  return false unless other.is_a?(Notification)
  @locations == other.locations && @message == other.message && @level == other.level && @thread_id == other.thread_id && @time_utc == other.time_utc && @exception == other.exception && @descriptor == other.descriptor && @associated_rule == other.associated_rule && @properties == other.properties
end

#hashObject



60
61
62
# File 'lib/sarif/notification.rb', line 60

def hash
  [@locations, @message, @level, @thread_id, @time_utc, @exception, @descriptor, @associated_rule, @properties].hash
end

#to_hObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sarif/notification.rb', line 20

def to_h
  h = {}
  h["locations"] = @locations&.map(&:to_h) if @locations&.any?
  h["message"] = @message&.to_h
  h["level"] = @level&.to_s if @level && @level != "warning"
  h["threadId"] = @thread_id unless @thread_id.nil?
  h["timeUtc"] = @time_utc unless @time_utc.nil?
  h["exception"] = @exception&.to_h unless @exception.nil?
  h["descriptor"] = @descriptor&.to_h unless @descriptor.nil?
  h["associatedRule"] = @associated_rule&.to_h unless @associated_rule.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



34
35
36
# File 'lib/sarif/notification.rb', line 34

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