Class: Git::Lint::Analyzers::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/git/lint/analyzers/abstract.rb

Overview

An abstract class which provides basic functionality from which all analyzers inherit from.

Constant Summary collapse

LEVELS =
%i[warn error].freeze
ISSUE_LINE_OFFSET =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commit:, settings: self.class.defaults) ⇒ Abstract

Returns a new instance of Abstract.



43
44
45
46
47
# File 'lib/git/lint/analyzers/abstract.rb', line 43

def initialize commit:, settings: self.class.defaults
  @commit = commit
  @settings = settings
  @filter_list = load_filter_list
end

Instance Attribute Details

#commitObject (readonly)

Returns the value of attribute commit.



41
42
43
# File 'lib/git/lint/analyzers/abstract.rb', line 41

def commit
  @commit
end

Class Method Details

.build_issue_line(index, line) ⇒ Object



37
38
39
# File 'lib/git/lint/analyzers/abstract.rb', line 37

def self.build_issue_line index, line
  {number: index + ISSUE_LINE_OFFSET, content: line}
end

.defaultsObject



29
30
31
# File 'lib/git/lint/analyzers/abstract.rb', line 29

def self.defaults
  fail NotImplementedError, "The `.#{__method__}` method must be implemented."
end

.descendantsObject



33
34
35
# File 'lib/git/lint/analyzers/abstract.rb', line 33

def self.descendants
  @descendants || []
end

.idObject



21
22
23
# File 'lib/git/lint/analyzers/abstract.rb', line 21

def self.id
  to_s.delete_prefix("Git::Lint::Analyzers").snakecase.to_sym
end

.inherited(klass) ⇒ Object



15
16
17
18
19
# File 'lib/git/lint/analyzers/abstract.rb', line 15

def self.inherited klass
  super
  @descendants ||= []
  @descendants << klass unless klass.to_s.start_with? "#<Class" # Ignore anonymous classes.
end

.labelObject



25
26
27
# File 'lib/git/lint/analyzers/abstract.rb', line 25

def self.label
  to_s.delete_prefix("Git::Lint::Analyzers").titleize
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/git/lint/analyzers/abstract.rb', line 49

def enabled?
  settings.fetch :enabled
end

#error?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/git/lint/analyzers/abstract.rb', line 71

def error?
  invalid? && severity == :error
end

#invalid?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/git/lint/analyzers/abstract.rb', line 63

def invalid?
  !valid?
end

#issueObject



75
76
77
# File 'lib/git/lint/analyzers/abstract.rb', line 75

def issue
  fail NotImplementedError, "The `##{__method__}` method must be implemented."
end

#severityObject



53
54
55
56
57
# File 'lib/git/lint/analyzers/abstract.rb', line 53

def severity
  settings.fetch(:severity).tap do |level|
    fail Errors::Severity, level unless LEVELS.include? level
  end
end

#valid?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/git/lint/analyzers/abstract.rb', line 59

def valid?
  fail NotImplementedError, "The `##{__method__}` method must be implemented."
end

#warning?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/git/lint/analyzers/abstract.rb', line 67

def warning?
  invalid? && severity == :warn
end