Skip to content

Commit

Permalink
First refactorings towards overrideable smell detectors
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jun 19, 2009
1 parent 63233bb commit 2b43377
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/reek/smells/smell_detector.rb
Expand Up @@ -34,8 +34,12 @@ def self.default_config
}
end

def self.create(config)
new(config[class_name])
end

def self.listen(hooks, config)
detector = new(config[class_name])
detector = create(config)
contexts.each { |ctx| hooks[ctx] << detector }
detector
end
Expand All @@ -51,6 +55,20 @@ def be_masked
@masked = true
end

def enabled?
@enabled
end

def configure(config)
my_part = config[self.class.name.split(/::/)[-1]]
return unless my_part
configure_with(my_part)
end

def configure_with(config)
@enabled = config[ENABLED_KEY] # if config.has_key?(ENABLED_KEY)
end

def examine(context)
before = @smells_found.size
examine_context(context) if @enabled and !exception?(context)
Expand Down
16 changes: 16 additions & 0 deletions spec/reek/smells/smell_detector_spec.rb
Expand Up @@ -2,6 +2,7 @@

require 'reek/report'
require 'reek/smells/duplication'
require 'reek/smells/large_class'

include Reek
include Reek::Smells
Expand All @@ -21,3 +22,18 @@
end
end

describe SmellDetector, 'configuration' do
# it 'stays enabled when not disabled' do
# @detector = LargeClass.new
# @detector.should be_enabled
# @detector.configure({'LargeClass' => {'max_methods' => 50}})
# @detector.should be_enabled
# end

it 'becomes disabled when disabled' do
@detector = LargeClass.new
@detector.should be_enabled
@detector.configure({'LargeClass' => {'enabled' => false}})
@detector.should_not be_enabled
end
end
1 change: 1 addition & 0 deletions tasks/build.rake
@@ -1,3 +1,4 @@
require 'rubygems'

namespace :build do
Rake::GemPackageTask.new($gemspec) do |task|
Expand Down

0 comments on commit 2b43377

Please sign in to comment.