lib/reek/smells/smell_detector.rb in reek-3.2.1 vs lib/reek/smells/smell_detector.rb in reek-3.3.0

- old
+ new

@@ -36,17 +36,22 @@ EXCLUDE_KEY => DEFAULT_EXCLUDE_SET.dup } end def inherited(subclass) - @subclasses ||= [] - @subclasses << subclass + subclasses << subclass end def descendants - @subclasses + subclasses end + + private + + def subclasses + @subclasses ||= [] + end end def smell_category self.class.smell_category end @@ -67,38 +72,38 @@ def default_smell_category name.split(/::/)[-1] end end - attr_reader :smells_found # SMELL: only published for tests + attr_reader :smells_found # SMELL: only published for tests def initialize(source, config = self.class.default_config) @source = source @config = SmellConfiguration.new(config) @smells_found = [] end def register(hooks) - return unless @config.enabled? + return unless config.enabled? self.class.contexts.each { |ctx| hooks[ctx] << self } end # SMELL: Getter (only used in 1 test) def enabled? - @config.enabled? + config.enabled? end - def configure_with(config) - @config.merge!(config) + def configure_with(new_config) + config.merge!(new_config) end def examine(context) return unless enabled_for? context return if exception?(context) sm = examine_context(context) - @smells_found += sm + self.smells_found += sm end def enabled_for?(context) enabled? && config_for(context)[SmellConfiguration::ENABLED_KEY] != false end @@ -106,18 +111,26 @@ def exception?(context) context.matches?(value(EXCLUDE_KEY, context, DEFAULT_EXCLUDE_SET)) end def report_on(report) - @smells_found.each { |smell| smell.report_on(report) } + smells_found.each { |smell| smell.report_on(report) } end def value(key, ctx, fall_back) - config_for(ctx)[key] || @config.value(key, ctx, fall_back) + config_for(ctx)[key] || config.value(key, ctx, fall_back) end def config_for(ctx) ctx.config_for(self.class) end + + protected + + attr_writer :smells_found + + private + + private_attr_reader :config end end end