Permalink
Browse files

Make 1.9 compatible.

Prepare infrastructure to support start and end of file events.
  • Loading branch information...
1 parent 6e862bd commit 14a0ea589413ad5f832aac7dfd63e0328de31706 Marty Andrews committed Dec 28, 2009
View
15 lib/roodi/checks/check.rb
@@ -12,13 +12,19 @@ def initialize
NODE_TYPES.each do |node|
start_node_method = "evaluate_start_#{node}"
end_node_method = "evaluate_end_#{node}"
- define_method(start_node_method) { } unless self.respond_to?(start_node_method)
- define_method(end_node_method) { } unless self.respond_to?(end_node_method)
+ define_method(start_node_method) { |node| return } unless self.respond_to?(start_node_method)
+ define_method(end_node_method) { |node| return } unless self.respond_to?(end_node_method)
end
def position(offset = 0)
"#{@line[2]}:#{@line[1] + offset}"
end
+
+ def start_file(filename)
+ end
+
+ def end_file(filename)
+ end
def evaluate_start(node)
end
@@ -42,8 +48,9 @@ def evaluate_node_end(node)
evaluate_end(node)
end
- def add_error(error)
- @errors << Roodi::Core::Error.new("#{@node.file}", "#{@node.line}", error)
+ def add_error(error, filename = @node.file, line = @node.line)
+ @errors ||= []
+ @errors << Roodi::Core::Error.new("#{filename}", "#{line}", error)
end
def errors
View
2 lib/roodi/checks/cyclomatic_complexity_check.rb
@@ -13,7 +13,7 @@ def initialize(complexity)
end
COMPLEXITY_NODE_TYPES.each do |type|
- define_method "evaluate_start_#{type}" do
+ define_method "evaluate_start_#{type}" do |node|
@count = @count + 1 if counting?
end
end
View
6 lib/roodi/core/checking_visitor.rb
@@ -13,14 +13,14 @@ def initialize(*checks)
end
end
- def visit(node)
+ def visit(node)
checks = @checks[node.node_type]
checks.each {|check| check.evaluate_node_start(node)} unless checks.nil?
- node.visitable_children.each {|sexp| sexp.accept(self)}
+ node.visitable_children.each {|sexp| sexp.accept(self)}
checks.each {|check| check.evaluate_node_end(node)} unless checks.nil?
- end
+ end
end
end
end
View
6 lib/roodi/core/runner.rb
@@ -21,12 +21,14 @@ def initialize(*checks)
def check(filename, content)
@checks ||= load_checks
@checker ||= CheckingVisitor.new(@checks)
+ @checks.each {|check| check.start_file(filename)}
node = parse(filename, content)
node.accept(@checker) if node
+ @checks.each {|check| check.end_file(filename)}
end
- def check_content(content)
- check("dummy-file.rb", content)
+ def check_content(content, filename = "dummy-file.rb")
+ check(filename, content)
end
def check_file(filename)

0 comments on commit 14a0ea5

Please sign in to comment.