Class: Reek::SmellWarning

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/reek/smell_warning.rb

Overview

Reports a warning that a smell has been found.

Instance Method Summary collapse

Constructor Details

#initialize(smell, context, warning) ⇒ SmellWarning

Returns a new instance of SmellWarning.



11
12
13
14
15
# File 'lib/reek/smell_warning.rb', line 11

def initialize(smell, context, warning)
  @smell = smell
  @context = context
  @warning = warning
end

Instance Method Details

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



21
22
23
# File 'lib/reek/smell_warning.rb', line 21

def <=>(other)
  report <=> other.report
end

#hashObject

:nodoc:



17
18
19
# File 'lib/reek/smell_warning.rb', line 17

def hash  # :nodoc:
  report.hash
end

#matches?(smell_class, patterns) ⇒ Boolean

Returns true only if this is a warning about an instance of smell_class and its report string matches all of the patterns.

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/reek/smell_warning.rb', line 31

def matches?(smell_class, patterns)
  return false unless smell_class.to_s == @smell.class.class_name
  rpt = report
  return patterns.all? {|exp| exp === rpt}
end

#reportObject

Returns a copy of the current report format (see Options) in which the following magic tokens have been substituted:

  • %s <– the name of the smell that was detected

  • %c <– a description of the CodeContext containing the smell

  • %w <– the specific problem that was detected



45
46
47
# File 'lib/reek/smell_warning.rb', line 45

def report
  Options[:format].gsub(/\%s/, @smell.smell_name).gsub(/\%c/, @context.to_s).gsub(/\%w/, @warning)
end