Class: Sarif::Fix

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

Overview

A proposed fix for the problem represented by a result object. A fix specifies a set of artifacts to modify. For each artifact, it specifies a set of bytes to remove, and provides a set of new bytes to replace them.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description: nil, artifact_changes:, properties: nil) ⇒ Fix

Returns a new instance of Fix.



8
9
10
11
12
# File 'lib/sarif/fix.rb', line 8

def initialize(description: nil, artifact_changes:, properties: nil)
  @description = description
  @artifact_changes = artifact_changes
  @properties = properties
end

Instance Attribute Details

#artifact_changesObject

Returns the value of attribute artifact_changes.



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

def artifact_changes
  @artifact_changes
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

Class Method Details

.from_hash(h) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/sarif/fix.rb', line 26

def self.from_hash(h)
  return nil if h.nil?
  new(
    description: Message.from_hash(h["description"]),
    artifact_changes: h["artifactChanges"]&.map { |v| ArtifactChange.from_hash(v) },
    properties: h["properties"]
  )
end

Instance Method Details

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



35
36
37
38
# File 'lib/sarif/fix.rb', line 35

def ==(other)
  return false unless other.is_a?(Fix)
  @description == other.description && @artifact_changes == other.artifact_changes && @properties == other.properties
end

#hashObject



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

def hash
  [@description, @artifact_changes, @properties].hash
end

#to_hObject



14
15
16
17
18
19
20
# File 'lib/sarif/fix.rb', line 14

def to_h
  h = {}
  h["description"] = @description&.to_h unless @description.nil?
  h["artifactChanges"] = @artifact_changes&.map(&:to_h)
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



22
23
24
# File 'lib/sarif/fix.rb', line 22

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