-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
50 lines (44 loc) · 1.72 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'rake'
$:.unshift File.expand_path(File.dirname(__FILE__) + "/lib")
require 'activr'
task :default => :list
task :list do
system 'rake -T'
end
##############################################################################
# SYNTAX CHECKING
##############################################################################
desc 'Check code syntax'
task :check_syntax do
`find . -name "*.rb" |xargs -n1 ruby -c |grep -v "Syntax OK"`
puts "* Done"
end
##############################################################################
# Stats
##############################################################################
desc 'Show some stats about the code'
task :stats do
line_count = proc do |path|
Dir[path].collect { |f| File.open(f).readlines.reject { |l| l =~ /(^\s*(\#|\/\*))|^\s*$/ }.size }.inject(0){ |sum,n| sum += n }
end
comment_count = proc do |path|
Dir[path].collect { |f| File.open(f).readlines.select { |l| l =~ /^\s*\#/ }.size }.inject(0) { |sum,n| sum += n }
end
lib = line_count['lib/**/*.rb']
comment = comment_count['lib/**/*.rb']
ext = line_count['ext/**/*.{c,h}']
spec = line_count['spec/**/*.rb']
comment_ratio = '%1.2f' % (comment.to_f / lib.to_f)
spec_ratio = '%1.2f' % (spec.to_f / lib.to_f)
puts '/======================\\'
puts '| Part LOC |'
puts '|======================|'
puts "| lib #{lib.to_s.ljust(5)}|"
puts "| lib comments #{comment.to_s.ljust(5)}|"
puts "| ext #{ext.to_s.ljust(5)}|"
puts "| spec #{spec.to_s.ljust(5)}|"
puts '| ratios: |'
puts "| lib/comment #{comment_ratio.to_s.ljust(5)}|"
puts "| lib/spec #{spec_ratio.to_s.ljust(5)}|"
puts '\======================/'
end