Parent

Class/Module Index [+]

Quicksearch

Reek::Smells::SmellDetector

Shared responsibilities of all smell detectors.

Constants

DEFAULT_EXCLUDE_SET

The default value for the EXCLUDE_KEY if it isn’t specified in any configuration file.

EXCLUDE_KEY

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.

Attributes

smells_found[R]

Public Class Methods

contexts() click to toggle source
# File lib/reek/smells/smell_detector.rb, line 32
def contexts
  [:defn, :defs]
end
default_config() click to toggle source
# File lib/reek/smells/smell_detector.rb, line 36
def default_config
  {
    Core::SmellConfiguration::ENABLED_KEY => true,
    EXCLUDE_KEY => DEFAULT_EXCLUDE_SET
  }
end
new(source, config = self.class.default_config) click to toggle source
# File lib/reek/smells/smell_detector.rb, line 46
def initialize(source, config = self.class.default_config)
  @source = source
  @config = Core::SmellConfiguration.new(config)
  @smells_found = []
end

Public Instance Methods

config_for(ctx) click to toggle source
# File lib/reek/smells/smell_detector.rb, line 89
def config_for(ctx)
  ctx.config[self.class.name.split(/::/)[-1]] || {}
  # BUG: needs to consider smell class AND subclass
end
configure_with(config) click to toggle source
# File lib/reek/smells/smell_detector.rb, line 62
def configure_with(config)
  @config.adopt!(config)
end
enabled?() click to toggle source

SMELL: Getter (only used in 1 test)

# File lib/reek/smells/smell_detector.rb, line 58
def enabled?
  @config.enabled?
end
examine(context) click to toggle source
# File lib/reek/smells/smell_detector.rb, line 66
def examine(context)
  enabled = @config.enabled? && config_for(context)[Core::SmellConfiguration::ENABLED_KEY] != false
  if enabled && !exception?(context)
    sm = examine_context(context)
    @smells_found += sm
  end
end
examine_context(context) click to toggle source
# File lib/reek/smells/smell_detector.rb, line 74
def examine_context(context)
end
exception?(context) click to toggle source
# File lib/reek/smells/smell_detector.rb, line 77
def exception?(context)
  context.matches?(value(EXCLUDE_KEY, context, DEFAULT_EXCLUDE_SET))
end
register(hooks) click to toggle source
# File lib/reek/smells/smell_detector.rb, line 52
def register(hooks)
  return unless @config.enabled?
  self.class.contexts.each { |ctx| hooks[ctx] << self }
end
report_on(report) click to toggle source
# File lib/reek/smells/smell_detector.rb, line 81
def report_on(report)
  @smells_found.each { |smell| smell.report_on(report) }
end
value(key, ctx, fall_back) click to toggle source
# File lib/reek/smells/smell_detector.rb, line 85
def value(key, ctx, fall_back)
  config_for(ctx)[key] || @config.value(key, ctx, fall_back)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.