Permalink
Browse files

Initial commit of KABLAME.

git-svn-id: http://kablame.googlecode.com/svn/trunk@2 fc056d42-643f-0410-81e7-b73d40e30204
  • Loading branch information...
1 parent 4caec93 commit 0c2310285f5dc159ed767ee7a51aee96a2fc88c2 @jdunphy committed Nov 21, 2007
Showing with 164 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +8 −0 README
  3. +22 −0 Rakefile
  4. +1 −0 init.rb
  5. +99 −0 lib/kablame.rb
  6. +14 −0 tasks/kablame_tasks.rake
View
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2007 Jacob Dunphy
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
8 README
@@ -0,0 +1,8 @@
+= Kablame 0.0.5
+
+So who really gets bragging rights?
+
+
+== Description
+
+Find out how many lines of test code each SVN contributor added, according to the almighty blame.
View
22 Rakefile
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the kablame plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the kablame plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Kablame'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
1 init.rb
@@ -0,0 +1 @@
+require 'kablame'
View
99 lib/kablame.rb
@@ -0,0 +1,99 @@
+class Kablame
+
+ def initialize()
+ @users = {}
+ end
+
+ def kablame
+ folders.each do |directory|
+
+ if File.exists?(directory)
+ puts "Processing #{directory}"
+ Dir.new(directory).entries.grep(file_format_regex).each do |filename|
+ process_file(directory +'/'+ filename)
+ end
+ else
+ puts "#{directory} not found. Skipping it!"
+ end
+ end
+ unless(@users.empty?)
+ print_results
+ else
+ puts "No results. Write some #{type.pluralize}!"
+ end
+ end
+
+ def process_file(filename)
+ lines = (`svn blame #{filename}`).split("\n")
+ puts "\t #{filename} -- #{lines.length} lines"
+ lines.each do |line|
+ name = line.match(/\d+[\ ]+(\w+)/)[1]
+ @users[name] ? @users[name].increment : @users[name] = User.new(name) unless name.nil?
+ end
+ end
+
+ def print_results
+ puts "++++++++++++TOTALS++++++++++++"
+ puts "**WINNER** #{@users.values.sort.first.name} **WINNER**"
+ @users.values.sort.each do |user|
+ puts user.to_s
+ end
+ puts "**LOSER** #{@users.values.sort.last.name} **LOSER**"
+ end
+
+
+ def folders
+ raise "this should be overridden by a subclass"
+ end
+
+ def file_format_regex
+ raise "this should be overridden by a subclass"
+ end
+
+ class User
+ attr_accessor :line_count
+ attr_accessor :name
+
+ def initialize(name)
+ @line_count = 1
+ @name = name
+ end
+
+ def <=>(other)
+ other.line_count <=> @line_count
+ end
+
+ def to_s
+ "#{@name}#{' '*(20 - @name.length)} ==> #{@line_count}"
+ end
+
+ def increment
+ @line_count = @line_count.next
+ end
+ end
+end
+
+class TestKablame < Kablame
+ def folders
+ ['test/unit','test/functional', 'test/integration']
+ end
+
+ def file_format_regex
+ /\.rb/
+ end
+
+ def type; "test"; end
+
+end
+
+class SpecKablame < Kablame
+ def folders
+ ['spec/models','spec/controllers','spec/views','spec/helpers']
+ end
+
+ def file_format_regex
+ /\.rb/
+ end
+
+ def type; "spec"; end
+end
View
14 tasks/kablame_tasks.rake
@@ -0,0 +1,14 @@
+
+namespace :kablame do
+ desc "KABLAME tests! See how much test code SVN says is yours"
+ task :tests => :environment do
+ require 'kablame'
+ TestKablame.new.kablame
+ end
+
+ desc "KABLAME specs! See how much of the specs SVN says is yours"
+ task :specs => :environment do
+ require 'kablame'
+ SpecKablame.new.kablame
+ end
+end

0 comments on commit 0c23102

Please sign in to comment.