Sha256: a9048f251c226b61fb6619bbd0c0de2c9d2e475c0f099a698a54e8fc8354f1ea

Contents?: true

Size: 1.56 KB

Versions: 15

Compression:

Stored size: 1.56 KB

Contents

class Class
  def name_words
    class_name = name.split(/::/)[-1]
    class_name.gsub(/([a-z])([A-Z])/) { |sub| "#{$1} #{$2}"}.split
  end
end

module Reek
  module Smells

    class SmellDetector

      # The name of the config field that lists the names of code contexts
      # that should not be checked. Add this field to the config for each
      # smell that should ignore this code element.
      EXCLUDE_KEY = 'exclude'

      # The name fo the config field that specifies whether a smell is
      # enabled. Set to +true+ or +false+.
      ENABLED_KEY = 'enabled'
      
      def self.class_name
        self.name.split(/::/)[-1]
      end

      def self.contexts      # :nodoc:
        [:defn, :defs]
      end
      
      def self.default_config
        {
          ENABLED_KEY => true,
          EXCLUDE_KEY => []
        }
      end

      def self.listen(hooks, config)
        detector = new(config[class_name])
        contexts.each { |ctx| hooks[ctx] << detector }
      end

      def initialize(config)
        @enabled = config[ENABLED_KEY]
        @exceptions = config[EXCLUDE_KEY]
      end

      def examine(context, report)
        before = report.size
        examine_context(context, report) if @enabled and !exception?(context)
        report.length > before
      end

      def examine_context(context, report)
      end
      
      def exception?(context)
        return false if @exceptions.nil? or @exceptions.length == 0
        context.matches?(@exceptions)
      end

      def smell_name
        self.class.name_words.join(' ')
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
kevinrutherford-reek-0.3.1.4 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-0.3.1.5 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-0.3.1.6 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-1.0.0 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-1.0.1 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-1.1.1 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-1.1.2.1 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-1.1.2 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-1.1.3.1 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-1.1.3.2 lib/reek/smells/smell_detector.rb
kevinrutherford-reek-1.1.3 lib/reek/smells/smell_detector.rb
teksymmetry-reek-1.1.3.1 lib/reek/smells/smell_detector.rb
teksymmetry-reek-1.1.3.2 lib/reek/smells/smell_detector.rb
reek-1.1.3 lib/reek/smells/smell_detector.rb
reek-1.0.0 lib/reek/smells/smell_detector.rb