lib/reek/smell_warning.rb in kevinrutherford-reek-1.1.3.8 vs lib/reek/smell_warning.rb in kevinrutherford-reek-1.1.3.9
- old
+ new
@@ -7,43 +7,49 @@
#
class SmellWarning
include Comparable
def initialize(smell, context, warning)
- @smell = smell
+ @detector = smell
@context = context
@warning = warning
+ @is_masked = smell.masked?
end
def hash # :nodoc:
- report.hash
+ basic_report.hash
end
def <=>(other)
- report <=> other.report
+ basic_report <=> other.basic_report
end
alias eql? <=> # :nodoc:
#
# Returns +true+ only if this is a warning about an instance of
# +smell_class+ and its report string matches all of the +patterns+.
#
def matches?(smell_class, patterns)
- return false unless smell_class.to_s == @smell.class.class_name
+ return false unless smell_class.to_s == @detector.class.class_name
rpt = report
return patterns.all? {|exp| exp === rpt}
end
+ def basic_report
+ Options[:format].gsub(/\%s/, @detector.smell_name).gsub(/\%c/, @context.to_s).gsub(/\%w/, @warning)
+ end
+
#
# 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
+ # * %m <-- "(is_masked) " if this is a is_masked smell
+ # * %s <-- the name of the smell that was detected
# * %w <-- the specific problem that was detected
#
def report
- Options[:format].gsub(/\%s/, @smell.smell_name).gsub(/\%c/, @context.to_s).gsub(/\%w/, @warning)
+ basic_report.gsub(/\%m/, @is_masked ? '(masked) ' : '')
end
end
end