Skip to content

Commit

Permalink
Removed LazyClass Analyser
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Mar 20, 2009
1 parent 25ac491 commit 28732f4
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 39 deletions.
6 changes: 3 additions & 3 deletions bin/reek
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
#

require 'reek'
require 'reek/options'
require 'reek/source'
require 'reek/options'

sources = Reek::Options.parse(ARGV)
exitstatus = 0
sources.each do |src|
warnings = Reek::Analyser.new(src).analyse
warnings = src.analyse
next if warnings.empty?
if sources.size == 1
puts warnings.to_s
else
puts "\"#{src.filename}\" -- #{warnings.length} warnings:"
puts "\"#{src}\" -- #{warnings.length} warnings:"
puts warnings.to_s
puts
end
Expand Down
26 changes: 1 addition & 25 deletions lib/reek.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
$:.unshift File.dirname(__FILE__)

require 'reek/code_parser'
require 'reek/report'
require 'reek/smells/smells'

module Reek # :doc:

VERSION = '0.3.1.1'

#
# Analyse the given source, looking for code smells.
# The source can be a filename or a String containing Ruby code.
# Returns a +Report+ listing the smells found.
#
class Analyser
def initialize(src)
@source = src
@config = SmellConfig.new
src.configure(@config)
end

#
# Returns a +Report+ listing the smells found.
#
def analyse
report = Report.new
smells = @config.smell_listeners
CodeParser.new(report, smells).check_source(@source.source)
report
end
end
end
1 change: 0 additions & 1 deletion lib/reek/code_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
require 'reek/method_context'
require 'reek/singleton_method_context'
require 'reek/yield_call_context'
require 'reek/smells/smells'

module Reek

Expand Down
1 change: 1 addition & 0 deletions lib/reek/smells/smells.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def load_local(file)
cf = YAML.load_file(rfile)
@config.value_merge!(cf)
end
self
end

def all_reekfiles(path)
Expand Down
22 changes: 18 additions & 4 deletions lib/reek/source.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
require 'reek/code_parser'

module Reek
class Source
attr_reader :source

def initialize(filename)
if File.exists?(filename)
@source = IO.readlines(filename).join
@dir = File.dirname(filename)
@filename = filename
else
@source = filename
@dir = '.'
@filename = "source code"
end
end

def configure(config)
config.load_local(@dir)
#
# Analyse the given source, looking for code smells.
# The source can be a filename or a String containing Ruby code.
# Returns a +Report+ listing the smells found.
#
def analyse
report = Report.new
smells = SmellConfig.new.load_local(@dir).smell_listeners
CodeParser.new(report, smells).check_source(@source)
report
end

def to_s
@filename
end
end
end
1 change: 0 additions & 1 deletion lib/reek/yield_call_context.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'reek/smells/smells'
require 'reek/code_context'

module Reek
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/script_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../spec_helper.rb'
require 'reek'

describe 'version number' do
it 'should report the correct value' do
Expand Down
4 changes: 2 additions & 2 deletions spec/reek/code_checks.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'reek'
require 'reek/source'
require 'reek/code_parser'
require 'reek/report'

Expand All @@ -9,7 +9,7 @@ module CodeChecks
def check(desc, src, expected, pending_str = nil)
it(desc) do
pending(pending_str) unless pending_str.nil?
rpt = Analyser.new(Source.new(src)).analyse
rpt = Source.new(src).analyse
rpt.length.should == expected.length
(0...rpt.length).each do |line|
expected[line].each { |patt| rpt[line].report.should match(patt) }
Expand Down
4 changes: 2 additions & 2 deletions spec/reek/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'reek/smells/smell_detector'
require 'reek/report'
require 'reek'
require 'reek/source'

include Reek

Expand All @@ -22,7 +22,7 @@

describe Report, "to_s" do
before(:each) do
rpt = Analyser.new(Source.new('def simple(a) a[3] end')).analyse
rpt = Source.new('def simple(a) a[3] end').analyse
@report = rpt.to_s.split("\n")
end

Expand Down

0 comments on commit 28732f4

Please sign in to comment.