Class: CC::Engine::Fingerprint

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/engine/fingerprint.rb

Overview

Calculates a unique fingerprint for an issue to allow for overriding

Constant Summary collapse

LINE_COUNT_STRIPPER =

Helps strip off the line counts from messages

Returns:

  • (Regexp)
/ \[.+\]$/
OVERRIDABLE_LINTERS =

A list of overridable linters to calculate fingerprints for

Returns:

  • (Hash)
%w[
  LineLength
  MultilineScript
  RuboCop
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(path, linter, message) ⇒ Fingerprint

Instantiates a new fingerprint

Examples:

CC::Engine::Fingerprint.new("a.haml", "LineLength", "Problem").empty?

Parameters:

  • path (String)

    the path of the file to fingerprint

  • linter (String)

    the name of the linter to fingerprint

  • message (String)

    the message to fingerprint


34
35
36
37
38
# File 'lib/cc/engine/fingerprint.rb', line 34

def initialize(path, linter, message)
  @linter = linter
  @message = message
  @path = path
end

Instance Method Details

#empty?Boolean

Checks whether the fingerprint is empty

Examples:

CC::Engine::Fingerprint.new("a.haml", "LineLength", "Problem").empty?#=> false

Returns:

  • (Boolean)

48
49
50
# File 'lib/cc/engine/fingerprint.rb', line 48

def empty?
  !OVERRIDABLE_LINTERS.include?(linter)
end

#to_sString

Converts the fingerprint to a string

Examples:

CC::Engine::Fingerprint.new("a.haml", "LineLength", "Problem").to_s#=> "md5digestedstring"

Returns:

  • (String)

60
61
62
63
64
65
66
67
68
# File 'lib/cc/engine/fingerprint.rb', line 60

def to_s
  return if empty?

  md5 = Digest::MD5.new
  md5 << path
  md5 << linter
  md5 << stripped_message
  md5.hexdigest
end