Class: Reek::CodeClimate::CodeClimateFingerprint

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/code_climate/code_climate_fingerprint.rb

Overview

Generates a string to uniquely identify a smell

Constant Summary collapse

NON_IDENTIFYING_PARAMETERS =
[:count, :depth].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(warning) ⇒ CodeClimateFingerprint

Returns a new instance of CodeClimateFingerprint.



11
12
13
# File 'lib/reek/code_climate/code_climate_fingerprint.rb', line 11

def initialize(warning)
  @warning = warning
end

Instance Attribute Details

#warningObject (readonly, private)

Returns the value of attribute warning.



25
26
27
# File 'lib/reek/code_climate/code_climate_fingerprint.rb', line 25

def warning
  @warning
end

Instance Method Details

#computeObject



15
16
17
18
19
20
21
# File 'lib/reek/code_climate/code_climate_fingerprint.rb', line 15

def compute
  return unless warning_uniquely_identifiable?

  identify_warning

  identifying_aspects.hexdigest.freeze
end

#identify_warningObject (private)



27
28
29
30
31
32
# File 'lib/reek/code_climate/code_climate_fingerprint.rb', line 27

def identify_warning
  identifying_aspects << warning.source
  identifying_aspects << warning.smell_type
  identifying_aspects << warning.context
  identifying_aspects << parameters
end

#identifying_aspectsObject (private)



34
35
36
# File 'lib/reek/code_climate/code_climate_fingerprint.rb', line 34

def identifying_aspects
  @identifying_aspects ||= Digest::MD5.new
end

#parametersObject (private)



38
39
40
# File 'lib/reek/code_climate/code_climate_fingerprint.rb', line 38

def parameters
  warning.parameters.except(*NON_IDENTIFYING_PARAMETERS).sort.to_s
end

#warning_uniquely_identifiable?Boolean (private)

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/reek/code_climate/code_climate_fingerprint.rb', line 42

def warning_uniquely_identifiable?
  # These could be identifiable if they had parameters
  ![
    'ManualDispatch',
    'NilCheck'
  ].include?(warning.smell_type)
end