Class: SemgrepWebApp::FindingLocation

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/semgrep_web_app/models/finding_location.rb

Overview

Location of the record in a file, as reported by Semgrep. If null, then the information does not exist or lacks integrity (older or broken scans)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(column: SKIP, end_column: SKIP, end_line: SKIP, file_path: SKIP, line: SKIP, additional_properties: nil) ⇒ FindingLocation

Returns a new instance of FindingLocation.



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/semgrep_web_app/models/finding_location.rb', line 60

def initialize(column: SKIP, end_column: SKIP, end_line: SKIP,
               file_path: SKIP, line: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @column = column unless column == SKIP
  @end_column = end_column unless end_column == SKIP
  @end_line = end_line unless end_line == SKIP
  @file_path = file_path unless file_path == SKIP
  @line = line unless line == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#columnInteger

Column at which the target starts

Returns:

  • (Integer)


15
16
17
# File 'lib/semgrep_web_app/models/finding_location.rb', line 15

def column
  @column
end

#end_columnInteger

Column at which the target ends

Returns:

  • (Integer)


19
20
21
# File 'lib/semgrep_web_app/models/finding_location.rb', line 19

def end_column
  @end_column
end

#end_lineInteger

Line at which the target ends

Returns:

  • (Integer)


23
24
25
# File 'lib/semgrep_web_app/models/finding_location.rb', line 23

def end_line
  @end_line
end

#file_pathString

File path of the relevant line and column numbers

Returns:

  • (String)


27
28
29
# File 'lib/semgrep_web_app/models/finding_location.rb', line 27

def file_path
  @file_path
end

#lineInteger

Line at which the target starts

Returns:

  • (Integer)


31
32
33
# File 'lib/semgrep_web_app/models/finding_location.rb', line 31

def line
  @line
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/semgrep_web_app/models/finding_location.rb', line 74

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  column = hash.key?('column') ? hash['column'] : SKIP
  end_column = hash.key?('end_column') ? hash['end_column'] : SKIP
  end_line = hash.key?('end_line') ? hash['end_line'] : SKIP
  file_path = hash.key?('file_path') ? hash['file_path'] : SKIP
  line = hash.key?('line') ? hash['line'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  FindingLocation.new(column: column,
                      end_column: end_column,
                      end_line: end_line,
                      file_path: file_path,
                      line: line,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
40
41
42
# File 'lib/semgrep_web_app/models/finding_location.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['column'] = 'column'
  @_hash['end_column'] = 'end_column'
  @_hash['end_line'] = 'end_line'
  @_hash['file_path'] = 'file_path'
  @_hash['line'] = 'line'
  @_hash
end

.nullablesObject

An array for nullable fields



56
57
58
# File 'lib/semgrep_web_app/models/finding_location.rb', line 56

def self.nullables
  []
end

.optionalsObject

An array for optional fields



45
46
47
48
49
50
51
52
53
# File 'lib/semgrep_web_app/models/finding_location.rb', line 45

def self.optionals
  %w[
    column
    end_column
    end_line
    file_path
    line
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (FindingLocation | Hash)

    value against the validation is performed.



102
103
104
105
106
107
108
# File 'lib/semgrep_web_app/models/finding_location.rb', line 102

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



119
120
121
122
123
124
# File 'lib/semgrep_web_app/models/finding_location.rb', line 119

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} column: #{@column.inspect}, end_column: #{@end_column.inspect}, end_line:"\
  " #{@end_line.inspect}, file_path: #{@file_path.inspect}, line: #{@line.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



111
112
113
114
115
116
# File 'lib/semgrep_web_app/models/finding_location.rb', line 111

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} column: #{@column}, end_column: #{@end_column}, end_line: #{@end_line},"\
  " file_path: #{@file_path}, line: #{@line}, additional_properties:"\
  " #{@additional_properties}>"
end