Class: Sarif::Log

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

Overview

Static Analysis Results Format (SARIF) Version 2.1.0 JSON Schema: a standard format for the output of static analysis tools.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_uri: nil, version:, runs:, inline_external_properties: nil, properties: nil) ⇒ Log

Returns a new instance of Log.



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

def initialize(schema_uri: nil, version:, runs:, inline_external_properties: nil, properties: nil)
  @schema_uri = schema_uri
  @version = version
  @runs = runs
  @inline_external_properties = inline_external_properties
  @properties = properties
end

Instance Attribute Details

#inline_external_propertiesObject

Returns the value of attribute inline_external_properties.



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

def inline_external_properties
  @inline_external_properties
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#runsObject

Returns the value of attribute runs.



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

def runs
  @runs
end

#schema_uriObject

Returns the value of attribute schema_uri.



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

def schema_uri
  @schema_uri
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.from_hash(h) ⇒ Object



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

def self.from_hash(h)
  return nil if h.nil?
  new(
    schema_uri: h["$schema"],
    version: h["version"],
    runs: h["runs"]&.map { |v| Run.from_hash(v) },
    inline_external_properties: h["inlineExternalProperties"]&.map { |v| ExternalProperties.from_hash(v) },
    properties: h["properties"]
  )
end

Instance Method Details

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



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

def ==(other)
  return false unless other.is_a?(Log)
  @schema_uri == other.schema_uri && @version == other.version && @runs == other.runs && @inline_external_properties == other.inline_external_properties && @properties == other.properties
end

#hashObject



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

def hash
  [@schema_uri, @version, @runs, @inline_external_properties, @properties].hash
end

#to_hObject



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

def to_h
  h = {}
  h["$schema"] = @schema_uri unless @schema_uri.nil?
  h["version"] = @version&.to_s
  h["runs"] = @runs&.map(&:to_h)
  h["inlineExternalProperties"] = @inline_external_properties&.map(&:to_h) if @inline_external_properties&.any?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



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

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