p8-metric_fu 0.9.0 → 0.9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -1
- data/Rakefile +19 -2
- data/TODO +2 -1
- data/lib/metric_fu/base.rb +29 -6
- data/lib/metric_fu/reek.rb +8 -0
- data/lib/metric_fu/roodi.rb +1 -1
- data/lib/metric_fu.rb +17 -3
- data/spec/churn_spec.rb +114 -114
- data/spec/config_spec.rb +103 -103
- data/spec/flay_spec.rb +16 -16
- data/spec/flog_spec.rb +204 -205
- data/spec/reek_spec.rb +23 -23
- data/spec/spec_helper.rb +24 -7
- metadata +2 -2
- data/lib/metric_fu/churn.rb +0 -88
- data/lib/metric_fu/flay.rb +0 -17
- data/lib/metric_fu/flog.rb +0 -129
- data/lib/metric_fu/md5_tracker.rb +0 -52
- data/lib/metric_fu/saikuro/saikuro.rb +0 -1214
- data/lib/tasks/churn.rake +0 -9
- data/lib/tasks/coverage.rake +0 -54
- data/lib/tasks/flay.rake +0 -6
- data/lib/tasks/flog.rake +0 -69
- data/lib/tasks/metric_fu.rake +0 -24
- data/lib/tasks/metric_fu.rb +0 -6
- data/lib/tasks/railroad.rake +0 -39
- data/lib/tasks/reek.rake +0 -6
- data/lib/tasks/roodi.rake +0 -7
- data/lib/tasks/saikuro.rake +0 -35
- data/lib/tasks/stats.rake +0 -14
- data/lib/templates/churn.html.erb +0 -22
- data/lib/templates/default.css +0 -45
- data/lib/templates/flay.html.erb +0 -30
- data/lib/templates/flog.html.erb +0 -38
- data/lib/templates/flog_page.html.erb +0 -25
- data/lib/templates/reek.html.erb +0 -30
- data/lib/templates/roodi.html.erb +0 -26
- data/spec/base_spec.rb +0 -57
data/spec/flay_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Flay do
|
4
4
|
|
5
|
-
describe "
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "template_name" do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
5
|
+
# describe "generate_output" do
|
6
|
+
# it "should create a new Generator and call generate_report on it" do
|
7
|
+
# @generator = MetricFu::Flay.new('other_dir')
|
8
|
+
# @generator.should_receive(:`).and_return("Matches found in :call (mass = 55)\n\tlib/metric_fu/flog_reporter.rb:2\n\tlib/metric_fu/flog_reporter.rb:3")
|
9
|
+
# @generator.generate_output
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# describe "template_name" do
|
14
|
+
# it "should return the class name in lowercase" do
|
15
|
+
# flay = MetricFu::Flay.new('base_dir')
|
16
|
+
# flay.template_name.should == 'flay'
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
end
|
data/spec/flog_spec.rb
CHANGED
@@ -1,208 +1,207 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
include MetricFu::Flog
|
3
2
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
AOM
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
MTHD
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
BM
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
IM
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
IM = <<-IM
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
IM
|
156
|
-
describe MetricFu::Flog do
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
3
|
+
describe Flog do
|
4
|
+
# before do
|
5
|
+
# @alpha_only_method = <<-AOM
|
6
|
+
# Total flog = 13.6283678106927
|
7
|
+
#
|
8
|
+
# ErrorMailer#errormail: (12.5)
|
9
|
+
# 12.0: assignment
|
10
|
+
# 1.2: []
|
11
|
+
# 1.2: now
|
12
|
+
# 1.2: content_type
|
13
|
+
# AOM
|
14
|
+
#
|
15
|
+
# @method_that_has_digits = <<-MTHD
|
16
|
+
# Total flog = 7.08378429936994
|
17
|
+
#
|
18
|
+
# NoImmunizationReason#to_c32: (7.1)
|
19
|
+
# 3.0: code
|
20
|
+
# 2.3: branch
|
21
|
+
# 1.4: templateId
|
22
|
+
# 1.2: act
|
23
|
+
# 1.1: entryRelationship
|
24
|
+
# MTHD
|
25
|
+
#
|
26
|
+
# @bang_method = <<-BM
|
27
|
+
# Total flog = 7.08378429936994
|
28
|
+
#
|
29
|
+
# NoImmunizationReason#to_c32!: (7.1)
|
30
|
+
# 3.0: code
|
31
|
+
# 2.3: branch
|
32
|
+
# 1.4: templateId
|
33
|
+
# 1.2: act
|
34
|
+
# 1.1: entryRelationship
|
35
|
+
# BM
|
36
|
+
#
|
37
|
+
# @invalid_method = <<-IM
|
38
|
+
# Total flog = 7.08378429936994
|
39
|
+
#
|
40
|
+
# 3.0: code
|
41
|
+
# 2.3: branch
|
42
|
+
# 1.4: templateId
|
43
|
+
# 1.2: act
|
44
|
+
# 1.1: entryRelationship
|
45
|
+
# IM
|
46
|
+
#
|
47
|
+
# @assignment_method = <<-MTHD
|
48
|
+
# Total Flog = 21.6 (5.4 +/- 3.3 flog / method)
|
49
|
+
#
|
50
|
+
# ActivityReport#existing_measure_attributes=: (8.5)
|
51
|
+
# 4.1: assignment
|
52
|
+
# 1.8: id
|
53
|
+
# 1.6: to_s
|
54
|
+
# 1.4: []
|
55
|
+
# 1.4: activity_report_measures
|
56
|
+
# 1.2: each
|
57
|
+
# 1.2: branch
|
58
|
+
# MTHD
|
59
|
+
#
|
60
|
+
# @class_methods_grouped_together = <<-MTHD
|
61
|
+
# Total Flog = 61.8 (7.7 +/- 95.3 flog / method)
|
62
|
+
#
|
63
|
+
# User#none: (32.8)
|
64
|
+
# 7.2: include
|
65
|
+
# 3.6: validates_length_of
|
66
|
+
# 3.6: validates_format_of
|
67
|
+
# 2.4: validates_presence_of
|
68
|
+
# 2.4: validates_uniqueness_of
|
69
|
+
# 1.4: bad_login_message
|
70
|
+
# 1.4: name_regex
|
71
|
+
# 1.4: bad_email_message
|
72
|
+
# 1.4: bad_name_message
|
73
|
+
# 1.4: login_regex
|
74
|
+
# 1.4: email_regex
|
75
|
+
# 1.2: private
|
76
|
+
# 1.2: has_and_belongs_to_many
|
77
|
+
# 1.2: before_create
|
78
|
+
# 1.2: attr_accessible
|
79
|
+
# 0.4: lit_fixnum
|
80
|
+
# MTHD
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# it "should be able to parse class_methods_grouped_together" do
|
84
|
+
# page = Base.parse(@class_methods_grouped_together)
|
85
|
+
# page.should_not be_nil
|
86
|
+
# page.score.should == 61.8
|
87
|
+
# page.scanned_methods.size.should == 1
|
88
|
+
# sm = page.scanned_methods.first
|
89
|
+
# sm.name.should == 'User#none'
|
90
|
+
# sm.score.should == 32.8
|
91
|
+
#
|
92
|
+
# sm.operators.size.should == 16
|
93
|
+
# sm.operators.first.score.should == 7.2
|
94
|
+
# sm.operators.first.operator.should == "include"
|
95
|
+
#
|
96
|
+
# sm.operators.last.score.should == 0.4
|
97
|
+
# sm.operators.last.operator.should == "lit_fixnum"
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# it "should be able to parse an assignment method" do
|
101
|
+
# page = Base.parse(@assignment_method)
|
102
|
+
# page.should_not be_nil
|
103
|
+
# page.score.should == 21.6
|
104
|
+
# page.scanned_methods.size.should == 1
|
105
|
+
# sm = page.scanned_methods.first
|
106
|
+
# sm.name.should == 'ActivityReport#existing_measure_attributes='
|
107
|
+
# sm.score.should == 8.5
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# it "should be able to parse an alpha only method" do
|
111
|
+
# page = Base.parse(@alpha_only_method)
|
112
|
+
# page.should_not be_nil
|
113
|
+
# page.score.should == 13.6283678106927
|
114
|
+
# page.scanned_methods.size.should == 1
|
115
|
+
# sm = page.scanned_methods.first
|
116
|
+
# sm.name.should == 'ErrorMailer#errormail'
|
117
|
+
# sm.score.should == 12.5
|
118
|
+
# end
|
119
|
+
#
|
120
|
+
# it "should be able to parse method that has digits" do
|
121
|
+
# page = Base.parse(@method_that_has_digits)
|
122
|
+
# page.should_not be_nil
|
123
|
+
# page.score.should == 7.08378429936994
|
124
|
+
# page.scanned_methods.size.should == 1
|
125
|
+
# sm = page.scanned_methods.first
|
126
|
+
# sm.name.should == 'NoImmunizationReason#to_c32'
|
127
|
+
# sm.score.should == 7.1
|
128
|
+
# end
|
129
|
+
#
|
130
|
+
# it "should be able to parse bang method" do
|
131
|
+
# page = Base.parse(@bang_method)
|
132
|
+
# page.should_not be_nil
|
133
|
+
# page.score.should == 7.08378429936994
|
134
|
+
# page.scanned_methods.size.should == 1
|
135
|
+
# sm = page.scanned_methods.first
|
136
|
+
# sm.name.should == 'NoImmunizationReason#to_c32!'
|
137
|
+
# sm.score.should == 7.1
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# it "should return nil when parsing invalid method" do
|
141
|
+
# page = Base.parse(@invalid_method)
|
142
|
+
# page.should be_nil
|
143
|
+
# end
|
144
|
+
# end
|
145
|
+
#
|
146
|
+
# IM = <<-IM
|
147
|
+
# Total flog = 7.08378429936994
|
148
|
+
#
|
149
|
+
# 3.0: code
|
150
|
+
# 2.3: branch
|
151
|
+
# 1.4: templateId
|
152
|
+
# 1.2: act
|
153
|
+
# 1.1: entryRelationship
|
154
|
+
# IM
|
155
|
+
# describe MetricFu::Flog do
|
156
|
+
#
|
157
|
+
# describe "generate_report" do
|
158
|
+
# it "should generate reports" do
|
159
|
+
# generator = Flog::Generator.new('other_dir')
|
160
|
+
# generator.should_receive(:flog_results).and_return(['A', 'B'])
|
161
|
+
# generator.should_receive(:save_output).at_least(3).times.and_return('')
|
162
|
+
# generator.should_receive(:open).any_number_of_times.and_return(['Total Flog = 1273.9 (9.3 +/- 259.2 flog / method)', 'TokenCounter#list_tokens_per_line: (15.2)', '9.0: assignment'].join("\n"))
|
163
|
+
# generator.generate_report
|
164
|
+
# end
|
165
|
+
#
|
166
|
+
# it "should be able to handle InvalidFlogs" do
|
167
|
+
# generator = Flog::Generator.new('other_dir')
|
168
|
+
# generator.should_receive(:flog_results).and_return(['A', 'B'])
|
169
|
+
# generator.should_receive(:inline_css).any_number_of_times.and_return('')
|
170
|
+
# generator.should_receive(:save_output).once
|
171
|
+
# generator.should_receive(:open).any_number_of_times.and_return(IM)
|
172
|
+
# generator.generate_report
|
173
|
+
# end
|
174
|
+
# end
|
175
|
+
#
|
176
|
+
# describe "template_name" do
|
177
|
+
# it "should return the class name in lowercase" do
|
178
|
+
# flog = Flog::Generator.new('base_dir')
|
179
|
+
# Flog::Generator.template_name.should == 'flog'
|
180
|
+
# end
|
181
|
+
# end
|
182
|
+
# end
|
183
|
+
#
|
184
|
+
# describe MetricFu::Flog::Page do
|
185
|
+
#
|
186
|
+
# describe "average_score" do
|
187
|
+
# it "should calculate the average score" do
|
188
|
+
# page = Page.new(10)
|
189
|
+
# page.should_receive(:scanned_methods).any_number_of_times.and_return([ScannedMethod.new(:test, 10), ScannedMethod.new(:test, 20)])
|
190
|
+
# page.average_score.should == 15
|
191
|
+
# end
|
192
|
+
#
|
193
|
+
# it "should be able to handle divide by zero" do
|
194
|
+
# page = Page.new(10)
|
195
|
+
# page.should_receive(:scanned_methods).any_number_of_times.and_return([])
|
196
|
+
# page.average_score.should == 0
|
197
|
+
# end
|
198
|
+
# end
|
199
|
+
#
|
200
|
+
# describe "highest_score" do
|
201
|
+
# it "should calculate the average score" do
|
202
|
+
# page = Page.new(10)
|
203
|
+
# page.should_receive(:scanned_methods).any_number_of_times.and_return([ScannedMethod.new(:test, 10), ScannedMethod.new(:test, 20)])
|
204
|
+
# page.highest_score.should == 20
|
205
|
+
# end
|
206
|
+
# end
|
183
207
|
end
|
184
|
-
|
185
|
-
describe MetricFu::Flog::Page do
|
186
|
-
|
187
|
-
describe "average_score" do
|
188
|
-
it "should calculate the average score" do
|
189
|
-
page = Page.new(10)
|
190
|
-
page.should_receive(:scanned_methods).any_number_of_times.and_return([ScannedMethod.new(:test, 10), ScannedMethod.new(:test, 20)])
|
191
|
-
page.average_score.should == 15
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should be able to handle divide by zero" do
|
195
|
-
page = Page.new(10)
|
196
|
-
page.should_receive(:scanned_methods).any_number_of_times.and_return([])
|
197
|
-
page.average_score.should == 0
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
describe "highest_score" do
|
202
|
-
it "should calculate the average score" do
|
203
|
-
page = Page.new(10)
|
204
|
-
page.should_receive(:scanned_methods).any_number_of_times.and_return([ScannedMethod.new(:test, 10), ScannedMethod.new(:test, 20)])
|
205
|
-
page.highest_score.should == 20
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
data/spec/reek_spec.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
REEK_RESULT = %("lib/metric_fu/base.rb" -- 5 warnings:
|
4
|
-
[Utility Function] #configuration doesn't depend on instance state
|
5
|
-
[Utility Function] #open_in_browser? doesn't depend on instance state
|
6
|
-
[Long Method] Configuration#reset has approx 6 statements
|
7
|
-
[Utility Function] Generator#cycle doesn't depend on instance state
|
8
|
-
[Utility Function] Generator#link_to_filename doesn't depend on instance state)
|
3
|
+
# REEK_RESULT = %("lib/metric_fu/base.rb" -- 5 warnings:
|
4
|
+
# [Utility Function] #configuration doesn't depend on instance state
|
5
|
+
# [Utility Function] #open_in_browser? doesn't depend on instance state
|
6
|
+
# [Long Method] Configuration#reset has approx 6 statements
|
7
|
+
# [Utility Function] Generator#cycle doesn't depend on instance state
|
8
|
+
# [Utility Function] Generator#link_to_filename doesn't depend on instance state)
|
9
|
+
#
|
10
|
+
describe Reek do
|
9
11
|
|
10
|
-
describe
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
12
|
+
# describe "generate_output" do
|
13
|
+
# it "should create a new Generator and call generate_report on it" do
|
14
|
+
# @generator = MetricFu::Reek.new('other_dir')
|
15
|
+
# @generator.should_receive(:`).and_return(REEK_RESULT)
|
16
|
+
# @generator.generate_output
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# describe "template_name" do
|
21
|
+
# it "should return the class name in lowercase" do
|
22
|
+
# flay = MetricFu::Reek.new('base_dir')
|
23
|
+
# flay.template_name.should == 'reek'
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,27 @@ require 'rubygems'
|
|
2
2
|
require 'spec'
|
3
3
|
require 'date'
|
4
4
|
|
5
|
-
require File.join(File.dirname(__FILE__), '/../lib/metric_fu
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
require File.join(File.dirname(__FILE__), '/../lib/metric_fu.rb')
|
6
|
+
include MetricFu
|
7
|
+
|
8
|
+
Mystat = <<-EOF
|
9
|
+
(in /Users/gmcinnes/Documents/projects/NeerBeer/src/Web)
|
10
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
11
|
+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
|
12
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
13
|
+
| Controllers | 893 | 405 | 16 | 41 | 2 | 7 |
|
14
|
+
| Helpers | 569 | 352 | 0 | 52 | 0 | 4 |
|
15
|
+
| Models | 1758 | 453 | 26 | 48 | 1 | 7 |
|
16
|
+
| Libraries | 2507 | 1320 | 19 | 175 | 9 | 5 |
|
17
|
+
| Model specs | 2285 | 965 | 0 | 1 | 0 | 963 |
|
18
|
+
| View specs | 821 | 654 | 0 | 2 | 0 | 325 |
|
19
|
+
| Controller specs | 1144 | 871 | 0 | 9 | 0 | 94 |
|
20
|
+
| Helper specs | 652 | 465 | 0 | 1 | 0 | 463 |
|
21
|
+
| Library specs | 1456 | 1141 | 8 | 14 | 1 | 79 |
|
22
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
23
|
+
| Total | 12085 | 6626 | 69 | 343 | 4 | 17 |
|
24
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
25
|
+
Code LOC: 2530 Test LOC: 4096 Code to Test Ratio: 1:1.6
|
26
|
+
|
27
|
+
EOF
|
28
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: p8-metric_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.0
|
4
|
+
version: 0.9.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Scruggs
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-02-
|
15
|
+
date: 2009-02-25 00:00:00 -08:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
data/lib/metric_fu/churn.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
module MetricFu
|
2
|
-
|
3
|
-
def self.generate_churn_report
|
4
|
-
Churn.generate_report(MetricFu.churn)
|
5
|
-
system("open #{Churn.metric_dir}/index.html") if open_in_browser?
|
6
|
-
end
|
7
|
-
|
8
|
-
class Churn < Base::Generator
|
9
|
-
|
10
|
-
def initialize(options={})
|
11
|
-
@base_dir = File.join(MetricFu::BASE_DIRECTORY, template_name)
|
12
|
-
if File.exist?(".git")
|
13
|
-
@source_control = Git.new(options[:start_date])
|
14
|
-
elsif File.exist?(".svn")
|
15
|
-
@source_control = Svn.new(options[:start_date])
|
16
|
-
else
|
17
|
-
raise "Churning requires a subversion or git repo"
|
18
|
-
end
|
19
|
-
|
20
|
-
@minimum_churn_count = options[:minimum_churn_count] || 5
|
21
|
-
end
|
22
|
-
|
23
|
-
def analyze
|
24
|
-
@changes = parse_log_for_changes.reject! {|file, change_count| change_count < @minimum_churn_count}
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def parse_log_for_changes
|
30
|
-
changes = {}
|
31
|
-
|
32
|
-
logs = @source_control.get_logs
|
33
|
-
logs.each do |line|
|
34
|
-
changes[line] ? changes[line] += 1 : changes[line] = 1
|
35
|
-
end
|
36
|
-
changes
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
class SourceControl
|
41
|
-
def initialize(start_date=nil)
|
42
|
-
@start_date = start_date
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
def require_rails_env
|
47
|
-
# not sure if the following works because active_support might only be in vendor/rails
|
48
|
-
# require 'activesupport'
|
49
|
-
require RAILS_ROOT + '/config/environment'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class Git < SourceControl
|
54
|
-
def get_logs
|
55
|
-
`git log #{date_range} --name-only --pretty=format:`.split(/\n/).reject{|line| line == ""}
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
def date_range
|
60
|
-
if @start_date
|
61
|
-
require_rails_env
|
62
|
-
"--after=#{@start_date.call.strftime('%Y-%m-%d')}"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
class Svn < SourceControl
|
69
|
-
def get_logs
|
70
|
-
`svn log #{date_range} --verbose`.split(/\n/).map { |line| clean_up_svn_line(line) }.compact
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
def date_range
|
75
|
-
if @start_date
|
76
|
-
require_rails_env
|
77
|
-
"--revision {#{@start_date.call.strftime('%Y-%m-%d')}}:{#{Time.now.strftime('%Y-%m-%d')}}"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def clean_up_svn_line(line)
|
82
|
-
m = line.match(/\W*[A,M]\W+(\/.*)\b/)
|
83
|
-
m ? m[1] : nil
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
data/lib/metric_fu/flay.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module MetricFu
|
2
|
-
|
3
|
-
def self.generate_flay_report
|
4
|
-
Flay.generate_report
|
5
|
-
system("open #{Flay.metric_dir}/index.html") if open_in_browser?
|
6
|
-
end
|
7
|
-
|
8
|
-
class Flay < Base::Generator
|
9
|
-
|
10
|
-
def analyze
|
11
|
-
files_to_flay = MetricFu.flay[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
12
|
-
output = `flay #{files_to_flay.join(" ")}`
|
13
|
-
@matches = output.chomp.split("\n\n").map{|m| m.split("\n ") }
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|