Introducing Autometric
Autometric is a tool thats automates the task of running metrics on your ruby code. It’s modeled after autotest, so it behaves the same way. Don’t waist any more time running rcov from the command line or rake task. Here’s a demo:
Or the full screen, if you prefer:
And here’s how to install it with images and all:
sudo gem install autometric
mkdir ~/.autometric_images
cd ~/.autometric_images
wget http://upload.wikimedia.org/wikipedia/commons/2/2e/Crystal_Clear_action_button_cancel.png -O coverage_failed.png
wget http://upload.wikimedia.org/wikipedia/commons/d/d6/Crystal_Clear_action_apply.png -O coverage_passed.png
wget http://upload.wikimedia.org/wikipedia/commons/2/2c/Crystal_Clear_action_stop.png -O cyclo_error.png
wget http://upload.wikimedia.org/wikipedia/commons/5/53/Crystal_Clear_app_error.png -O cyclo_warn.png
wget http://upload.wikimedia.org/wikipedia/commons/b/b9/Crystal_Clear_action_edit_remove.png -O decrease.png
wget http://upload.wikimedia.org/wikipedia/commons/e/e2/Crystal_Clear_action_edit_add.png -O increase.png
wget http://upload.wikimedia.org/wikipedia/commons/0/0a/Crystal_Clear_action_1downarrow.png -O flog_decrease.png
wget http://upload.wikimedia.org/wikipedia/commons/2/2c/Crystal_Clear_action_1uparrow.png -O flog_increase.png
wget http://upload.wikimedia.org/wikipedia/commons/0/03/Crystal_Clear_action_bookmark.png -O flog.png
And save the following as “.autometric” in your home directory:
def growl(title, msg, pri=0, stick="", image="")
image_arg = (!image.empty?) ? "--image #{image}" : ""
system "growlnotify -n autometric #{image_arg} -p #{pri} -m \"#{msg}\" #{title} #{stick}"
end
Autocoverage.add_hook :initialize do |at|
at.threshold = 90.0
end
Autocoverage.add_hook :failed do |at|
growl("Code Coverage Failed","#{at.coverage}% code coverage", 2, "", "~/.autometric_images/coverage_failed.png")
end
Autocoverage.add_hook :passed do |at|
growl("Code Coverage Passed", "#{at.coverage}% code coverage", -2, "", "~/.autometric_images/coverage_passed.png") #if at.tainted
end
Autocoverage.add_hook :increased do |at|
growl("Code Coverage Increased","#{"%.3f" % (at.coverage - at.previous_coverage)}% code coverage increase", 2, "", "~/.autometric_images/increase.png")
end
Autocoverage.add_hook :decreased do |at|
growl("Code Coverage Decreased", "#{"%.3f" % (at.previous_coverage - at.coverage)}% code coverage decrease", -2, "", "~/.autometric_images/decrease.png") #if at.tainted
end
Autocyclo.add_hook :erred do |at|
lines = at.errors.collect {|e| "#{e[:rating]} #{e[:id]}" }
message = lines.length > 5 ? lines[0...5].join("\n") + "\n..." : lines.join("\n")
growl("Cyclomatic Complexity Errors", message, 1, "", "~/.autometric_images/cyclo_error.png")
end
Autocyclo.add_hook :warned do |at|
lines = at.warnings.collect {|w| "#{w[:rating]} #{w[:id]}" }
message = lines.length > 5 ? lines[0...5].join("\n") + "\n..." : lines.join("\n")
growl("Cyclomatic Complexity Warnings", "#{message}", 2, "", "~/.autometric_images/cyclo_warn.png")
end
Autotoken.add_hook :erred do |at|
lines = at.errors.collect {|e| "#{e[:rating]} #{e[:id]}" }
message = lines.length > 5 ? lines[0...5].join("\n") + "\n..." : lines.join("\n")
growl("Token Complexity Errors", message, 1, "", "~/.autometric_images/cyclo_error.png")
end
Autotoken.add_hook :warned do |at|
lines = at.warnings.collect {|w| "#{w[:rating]} #{w[:id]}" }
message = lines.length > 5 ? lines[0...5].join("\n") + "\n..." : lines.join("\n")
growl("Token Complexity Warnings", "#{message}", 2, "", "~/.autometric_images/cyclo_warn.png")
end
Autoflog.add_hook :flogged do |at|
growl("Flog Score", "#{"%.3f" % at.score}", 2, "", "~/.autometric_images/flog.png")
end
Autoflog.add_hook :increased do |at|
growl("Flog Score Increased", "#{"%.3f" % (at.score - at.previous_score)}", -2, "", "~/.autometric_images/flog_increase.png")
end
Autoflog.add_hook :decreased do |at|
growl("Flog Score Decreased", "#{"%.3f" % (at.previous_score - at.score)}", -2, "", "~/.autometric_images/flog_decrease.png")
end
Enjoy.
1 comment
Comments
-
You might just want to package this as a rake or sake task. Might be easier.
