Class: Sarif::ReportingConfiguration

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

Overview

Information about a rule or notification that can be configured at runtime.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enabled: true, level: "warning", rank: -1.0,, parameters: nil, properties: nil) ⇒ ReportingConfiguration

Returns a new instance of ReportingConfiguration.



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

def initialize(enabled: true, level: "warning", rank: -1.0, parameters: nil, properties: nil)
  @enabled = enabled
  @level = level
  @rank = rank
  @parameters = parameters
  @properties = properties
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

#parametersObject

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#rankObject

Returns the value of attribute rank.



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

def rank
  @rank
end

Class Method Details

.from_hash(h) ⇒ Object



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

def self.from_hash(h)
  return nil if h.nil?
  new(
    enabled: h.key?("enabled") ? h["enabled"] : true,
    level: h["level"] || "warning",
    rank: h["rank"] || -1.0,
    parameters: h["parameters"],
    properties: h["properties"]
  )
end

Instance Method Details

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



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

def ==(other)
  return false unless other.is_a?(ReportingConfiguration)
  @enabled == other.enabled && @level == other.level && @rank == other.rank && @parameters == other.parameters && @properties == other.properties
end

#hashObject



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

def hash
  [@enabled, @level, @rank, @parameters, @properties].hash
end

#to_hObject



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

def to_h
  h = {}
  h["enabled"] = @enabled unless @enabled
  h["level"] = @level&.to_s if @level && @level != "warning"
  h["rank"] = @rank if @rank && @rank != -1
  h["parameters"] = @parameters unless @parameters.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



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

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