Class: Sarif::Notification
- Inherits:
-
Object
- Object
- Sarif::Notification
- 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
-
#associated_rule ⇒ Object
Returns the value of attribute associated_rule.
-
#descriptor ⇒ Object
Returns the value of attribute descriptor.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#level ⇒ Object
Returns the value of attribute level.
-
#locations ⇒ Object
Returns the value of attribute locations.
-
#message ⇒ Object
Returns the value of attribute message.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#thread_id ⇒ Object
Returns the value of attribute thread_id.
-
#time_utc ⇒ Object
Returns the value of attribute time_utc.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(locations: [], message:, level: "warning", thread_id: nil, time_utc: nil, exception: nil, descriptor: nil, associated_rule: nil, properties: nil) ⇒ Notification
constructor
A new instance of Notification.
- #to_h ⇒ Object
- #to_json(pretty: false) ⇒ Object
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 = @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_rule ⇒ Object
Returns the value of attribute associated_rule.
6 7 8 |
# File 'lib/sarif/notification.rb', line 6 def associated_rule @associated_rule end |
#descriptor ⇒ Object
Returns the value of attribute descriptor.
6 7 8 |
# File 'lib/sarif/notification.rb', line 6 def descriptor @descriptor end |
#exception ⇒ Object
Returns the value of attribute exception.
6 7 8 |
# File 'lib/sarif/notification.rb', line 6 def exception @exception end |
#level ⇒ Object
Returns the value of attribute level.
6 7 8 |
# File 'lib/sarif/notification.rb', line 6 def level @level end |
#locations ⇒ Object
Returns the value of attribute locations.
6 7 8 |
# File 'lib/sarif/notification.rb', line 6 def locations @locations end |
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/sarif/notification.rb', line 6 def @message end |
#properties ⇒ Object
Returns the value of attribute properties.
6 7 8 |
# File 'lib/sarif/notification.rb', line 6 def properties @properties end |
#thread_id ⇒ Object
Returns the value of attribute thread_id.
6 7 8 |
# File 'lib/sarif/notification.rb', line 6 def thread_id @thread_id end |
#time_utc ⇒ Object
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. && @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 |
#hash ⇒ Object
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_h ⇒ Object
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 |