Class: EagerEye::Issue

Inherits:
Object
  • Object
show all
Defined in:
lib/eager_eye/issue.rb

Constant Summary collapse

VALID_SEVERITIES =
%i[warning error].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(detector:, file_path:, line_number:, message:, severity: :warning, suggestion: nil) ⇒ Issue

Returns a new instance of Issue.



9
10
11
12
13
14
15
16
# File 'lib/eager_eye/issue.rb', line 9

def initialize(detector:, file_path:, line_number:, message:, severity: :warning, suggestion: nil)
  @detector = detector
  @file_path = file_path
  @line_number = line_number
  @message = message
  @severity = validate_severity(severity)
  @suggestion = suggestion
end

Instance Attribute Details

#detectorObject (readonly)

Returns the value of attribute detector.



5
6
7
# File 'lib/eager_eye/issue.rb', line 5

def detector
  @detector
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



5
6
7
# File 'lib/eager_eye/issue.rb', line 5

def file_path
  @file_path
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



5
6
7
# File 'lib/eager_eye/issue.rb', line 5

def line_number
  @line_number
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/eager_eye/issue.rb', line 5

def message
  @message
end

#severityObject (readonly)

Returns the value of attribute severity.



5
6
7
# File 'lib/eager_eye/issue.rb', line 5

def severity
  @severity
end

#suggestionObject (readonly)

Returns the value of attribute suggestion.



5
6
7
# File 'lib/eager_eye/issue.rb', line 5

def suggestion
  @suggestion
end

Instance Method Details

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



33
34
35
36
37
38
39
40
41
42
# File 'lib/eager_eye/issue.rb', line 33

def ==(other)
  return false unless other.is_a?(Issue)

  detector == other.detector &&
    file_path == other.file_path &&
    line_number == other.line_number &&
    message == other.message &&
    severity == other.severity &&
    suggestion == other.suggestion
end

#hashObject



46
47
48
# File 'lib/eager_eye/issue.rb', line 46

def hash
  [detector, file_path, line_number, message, severity, suggestion].hash
end

#to_hObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/eager_eye/issue.rb', line 18

def to_h
  {
    detector: detector,
    file_path: file_path,
    line_number: line_number,
    message: message,
    severity: severity,
    suggestion: suggestion
  }
end

#to_json(*args) ⇒ Object



29
30
31
# File 'lib/eager_eye/issue.rb', line 29

def to_json(*args)
  to_h.to_json(*args)
end