code_statistics 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/code_statistics.gemspec +2 -2
- data/lib/code_statistics/code_statistics.rb +18 -3
- data/lib/tasks/code_stats.rb +8 -2
- data/test/code_statistics_test.rb +28 -8
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/code_statistics.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{code_statistics}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dan Mayer"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-18}
|
13
13
|
s.description = %q{"This is a port of the rails 'rake stats' method so it can be made more robust and work for non rails projects. New features may eventually be added as well."}
|
14
14
|
s.email = %q{dan@devver.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -3,11 +3,12 @@ module CodeStatistics
|
|
3
3
|
|
4
4
|
attr_reader :print_buffer
|
5
5
|
|
6
|
-
def initialize(
|
6
|
+
def initialize(pairs, ignore_file_globs = [])
|
7
7
|
@pairs = pairs
|
8
8
|
@test_types = []
|
9
9
|
@print_buffer = ""
|
10
10
|
directory = Dir.pwd
|
11
|
+
@ignore_files = collect_files_to_ignore(ignore_file_globs)
|
11
12
|
|
12
13
|
directories_to_search = ['app','test','spec','merb','features', 'bin']
|
13
14
|
recursively_add_directories(directories_to_search)
|
@@ -37,6 +38,14 @@ module CodeStatistics
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
41
|
+
|
42
|
+
def collect_files_to_ignore(ignore_file_globs)
|
43
|
+
files_to_remove = []
|
44
|
+
ignore_file_globs.each do |glob|
|
45
|
+
files_to_remove.concat(Dir[glob])
|
46
|
+
end
|
47
|
+
files_to_remove.map{ |filepath| File.expand_path(filepath)}
|
48
|
+
end
|
40
49
|
|
41
50
|
def to_s
|
42
51
|
@print_buffer = ''
|
@@ -70,18 +79,24 @@ module CodeStatistics
|
|
70
79
|
@test_types << test_type
|
71
80
|
end
|
72
81
|
|
82
|
+
def ignore_file?(file_path)
|
83
|
+
@ignore_files.include?(File.expand_path(file_path))
|
84
|
+
end
|
85
|
+
|
73
86
|
def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
|
74
87
|
stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
|
75
88
|
|
76
89
|
Dir.foreach(directory) do |file_name|
|
77
90
|
if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
|
78
|
-
newstats = calculate_directory_statistics(directory
|
91
|
+
newstats = calculate_directory_statistics(File.join(directory,file_name), pattern)
|
79
92
|
stats.each { |k, v| stats[k] += newstats[k] }
|
80
93
|
end
|
81
94
|
|
82
95
|
next unless file_name =~ pattern
|
96
|
+
file_path = File.join(directory, file_name)
|
97
|
+
next if ignore_file?(file_path)
|
83
98
|
|
84
|
-
f = File.open(
|
99
|
+
f = File.open(file_path)
|
85
100
|
|
86
101
|
while line = f.gets
|
87
102
|
stats["lines"] += 1
|
data/lib/tasks/code_stats.rb
CHANGED
@@ -13,15 +13,21 @@ if ENV['DIRECTORIES_TO_CALCULATE']
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
if ENV['IGNORE_FILE_GLOBS']
|
17
|
+
user_ignored_dirs = ENV['IGNORE_FILE_GLOBS'].split(',')
|
18
|
+
else
|
19
|
+
user_ignored_dirs = []
|
20
|
+
end
|
21
|
+
|
16
22
|
desc "Report code statistics (KLOCs, etc) from the application"
|
17
23
|
task :stats do
|
18
24
|
require File.join(File.dirname(__FILE__), '..', 'code_statistics', 'code_statistics')
|
19
|
-
puts CodeStatistics::CodeStatistics.new(
|
25
|
+
puts CodeStatistics::CodeStatistics.new(stats_directories, user_ignored_dirs).to_s
|
20
26
|
end
|
21
27
|
|
22
28
|
#this is for apps that already had a stats task, but want to use the newer features of this gem
|
23
29
|
desc "Report code statistics (KLOCs, etc) from the application"
|
24
30
|
task :code_stats do
|
25
31
|
require File.join(File.dirname(__FILE__), '..', 'code_statistics', 'code_statistics')
|
26
|
-
puts CodeStatistics::CodeStatistics.new(
|
32
|
+
puts CodeStatistics::CodeStatistics.new(stats_directories, user_ignored_dirs).to_s
|
27
33
|
end
|
@@ -10,7 +10,7 @@ class CodeStatisticsTest < Test::Unit::TestCase
|
|
10
10
|
file = dir.file("real.rb", "this\nis\n\lame\n")
|
11
11
|
controllers_dir = dir.directory("controllers")
|
12
12
|
file = controllers_dir.file("fake.rb", "this\nis\n\lame\n")
|
13
|
-
code_stats = CodeStatistics::CodeStatistics.new(["Libraries", 'lib'])
|
13
|
+
code_stats = CodeStatistics::CodeStatistics.new([["Libraries", 'lib']])
|
14
14
|
assert code_stats.to_s.match(/Libraries/)
|
15
15
|
assert code_stats.to_s.match(/Code LOC: 6/)
|
16
16
|
end
|
@@ -21,7 +21,7 @@ class CodeStatisticsTest < Test::Unit::TestCase
|
|
21
21
|
dir = construct.directory("app")
|
22
22
|
controllers_dir = dir.directory("controllers")
|
23
23
|
file = controllers_dir.file("fake.rb", "this\nis\n\lame\n")
|
24
|
-
code_stats = CodeStatistics::CodeStatistics.new()
|
24
|
+
code_stats = CodeStatistics::CodeStatistics.new([])
|
25
25
|
assert code_stats.to_s.match(/App\/controllers/)
|
26
26
|
assert code_stats.to_s.match(/Code LOC: 3/)
|
27
27
|
end
|
@@ -32,7 +32,7 @@ class CodeStatisticsTest < Test::Unit::TestCase
|
|
32
32
|
dir = construct.directory("app")
|
33
33
|
sub_dir = dir.directory("servers")
|
34
34
|
file = sub_dir.file("fake.rb", "this\nis\n\lame\n")
|
35
|
-
code_stats = CodeStatistics::CodeStatistics.new()
|
35
|
+
code_stats = CodeStatistics::CodeStatistics.new([])
|
36
36
|
assert code_stats.to_s.match(/App\/servers/)
|
37
37
|
assert code_stats.to_s.match(/Code LOC: 3/)
|
38
38
|
end
|
@@ -45,7 +45,7 @@ class CodeStatisticsTest < Test::Unit::TestCase
|
|
45
45
|
file = sub_dir.file("fake.rb", "this\nis\n\lame\n")
|
46
46
|
sub_dir2 = dir.directory("controllers")
|
47
47
|
file = sub_dir2.file("fake.rb", "this\nis\n\lame\n")
|
48
|
-
code_stats = CodeStatistics::CodeStatistics.new()
|
48
|
+
code_stats = CodeStatistics::CodeStatistics.new([])
|
49
49
|
assert code_stats.to_s.match(/Spec\/models/)
|
50
50
|
assert code_stats.to_s.match(/Spec\/controllers/)
|
51
51
|
assert code_stats.to_s.match(/Test LOC: 6/)
|
@@ -56,7 +56,7 @@ class CodeStatisticsTest < Test::Unit::TestCase
|
|
56
56
|
within_construct do |construct|
|
57
57
|
dir = construct.directory("spec")
|
58
58
|
file = dir.file("fake.rb", "this\nis\n\lame\n")
|
59
|
-
code_stats = CodeStatistics::CodeStatistics.new()
|
59
|
+
code_stats = CodeStatistics::CodeStatistics.new([])
|
60
60
|
assert code_stats.to_s.match(/Spec/)
|
61
61
|
assert code_stats.to_s.match(/Test LOC: 3/)
|
62
62
|
end
|
@@ -69,7 +69,7 @@ class CodeStatisticsTest < Test::Unit::TestCase
|
|
69
69
|
file = sub_dir.file("fake.rb", "this\nis\n\lame\n")
|
70
70
|
sub_dir2 = dir.directory("controllers")
|
71
71
|
file = sub_dir2.file("fake.rb", "this\nis\n\lame\n")
|
72
|
-
code_stats = CodeStatistics::CodeStatistics.new()
|
72
|
+
code_stats = CodeStatistics::CodeStatistics.new([])
|
73
73
|
assert code_stats.to_s.match(/Test\/models/)
|
74
74
|
assert code_stats.to_s.match(/Test\/controllers/)
|
75
75
|
assert code_stats.to_s.match(/Test LOC: 6/)
|
@@ -80,7 +80,7 @@ class CodeStatisticsTest < Test::Unit::TestCase
|
|
80
80
|
within_construct do |construct|
|
81
81
|
dir = construct.directory("test")
|
82
82
|
file = dir.file("fake.rb", "this\nis\n\lame\n")
|
83
|
-
code_stats = CodeStatistics::CodeStatistics.new()
|
83
|
+
code_stats = CodeStatistics::CodeStatistics.new([])
|
84
84
|
assert code_stats.to_s.match(/Test/)
|
85
85
|
assert code_stats.to_s.match(/Test LOC: 3/)
|
86
86
|
end
|
@@ -99,12 +99,32 @@ class CodeStatisticsTest < Test::Unit::TestCase
|
|
99
99
|
file = sub_dir.file("fake.rb", "this\nis\n\lame\n")
|
100
100
|
sub_dir2 = dir.directory("controllers")
|
101
101
|
file = sub_dir2.file("fake.rb", "this\nis\n\lame\n")
|
102
|
-
code_stats = CodeStatistics::CodeStatistics.new()
|
102
|
+
code_stats = CodeStatistics::CodeStatistics.new([])
|
103
103
|
assert code_stats.to_s.match(/Code LOC: 12/)
|
104
104
|
assert code_stats.to_s.match(/Test LOC: 6/)
|
105
105
|
assert code_stats.to_s.match(/Code to Test Ratio: 1:0.5/)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
should "ignore the expected file globs" do
|
110
|
+
within_construct do |construct|
|
111
|
+
dir = construct.directory("app")
|
112
|
+
sub_dir = dir.directory("models")
|
113
|
+
file = sub_dir.file("fake.rb", "this\n"*9)
|
114
|
+
sub_dir2 = dir.directory("controllers")
|
115
|
+
file = sub_dir2.file("fake.rb", "this\nis\n\lame\n")
|
116
|
+
|
117
|
+
dir = construct.directory("test")
|
118
|
+
sub_dir = dir.directory("models")
|
119
|
+
file = sub_dir.file("fake.rb", "this\nis\n\lame\n")
|
120
|
+
sub_dir2 = dir.directory("controllers")
|
121
|
+
file = sub_dir2.file("fake.rb", "this\nis\n\lame\n")
|
122
|
+
code_stats = CodeStatistics::CodeStatistics.new([],['app/controllers/**/*'])
|
123
|
+
assert code_stats.to_s.match(/Code LOC: 9/)
|
124
|
+
assert code_stats.to_s.match(/Test LOC: 6/)
|
125
|
+
assert code_stats.to_s.match(/Code to Test Ratio: 1:0.7/)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
109
129
|
|
110
130
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_statistics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Mayer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-18 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|