Sha256: de47226f4a0da5f19c6aa634548083b3f51f52c1047a69ebded7f90a65190339

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

module Reek

  #
  # Reports a warning that a smell has been found.
  #
  class SmellWarning
    include Comparable

    def initialize(smell, context, warning, masked)
      @detector = smell
      @context = context
      @warning = warning
      @is_masked = masked
    end

    def hash  # :nodoc:
      sort_key.hash
    end

    def <=>(other)
      sort_key <=> other.sort_key
    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 == @detector.class.class_name
      contains_all?(patterns)
    end

    def contains_all?(patterns)
      rpt = sort_key.to_s
      return patterns.all? {|exp| exp === rpt}
    end

    def sort_key
      [@context.to_s, @warning, @detector.smell_name]
    end

    protected :sort_key

    def report(format)
      format.gsub(/\%s/, @detector.smell_name).gsub(/\%c/, @context.to_s).gsub(/\%w/, @warning).gsub(/\%m/, @is_masked ? '(masked) ' : '')
    end

    def report_on(report)
      if @is_masked
        report.record_masked_smell(self)
      else
        report << self
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reek-1.2.3 lib/reek/smell_warning.rb
reek-1.2.2 lib/reek/smell_warning.rb
reek-1.2.1 lib/reek/smell_warning.rb