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 for all analyzers to inherit from.

Constant Summary collapse

LEVELS =
%w[warn error].freeze
BODY_OFFSET =
3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commit) ⇒ Abstract

Returns a new instance of Abstract.



26
27
28
29
30
# File 'lib/git/lint/analyzers/abstract.rb', line 26

def initialize(commit, **)
  super(**)
  @commit = commit
  @filter_list = load_filter_list
end

Instance Attribute Details

#commitObject (readonly)

Returns the value of attribute commit.



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

def commit
  @commit
end

Class Method Details

.build_issue_line(index, line) ⇒ Object



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

def self.build_issue_line(index, line) = {number: index + BODY_OFFSET, content: line}

.idObject



18
# File 'lib/git/lint/analyzers/abstract.rb', line 18

def self.id = to_s.delete_prefix!("Git::Lint::Analyzers").snakecase

.labelObject



20
# File 'lib/git/lint/analyzers/abstract.rb', line 20

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

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


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

def error? = invalid? && severity == "error"

#invalid?Boolean

Returns:

  • (Boolean)


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

def invalid? = !valid?

#issueObject



45
# File 'lib/git/lint/analyzers/abstract.rb', line 45

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

#severityObject



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

def severity
  settings.public_send("#{self.class.id}_severity".sub("commit_", "commits_"))
          .tap { |level| fail Errors::Severity, level unless LEVELS.include? level }
end

#valid?Boolean

Returns:

  • (Boolean)


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

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

#warning?Boolean

Returns:

  • (Boolean)


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

def warning? = invalid? && severity == "warn"