p8-metric_fu 0.8.0.16 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +17 -63
- data/Rakefile +1 -1
- data/lib/metric_fu/base.rb +8 -114
- data/lib/metric_fu/churn.rb +7 -8
- data/lib/metric_fu/flay_reporter.rb +17 -0
- data/lib/metric_fu/flog_reporter/base.rb +49 -0
- data/lib/metric_fu/flog_reporter/generator.rb +39 -0
- data/lib/metric_fu/flog_reporter/operator.rb +10 -0
- data/lib/metric_fu/flog_reporter/page.rb +33 -0
- data/lib/metric_fu/flog_reporter/scanned_method.rb +28 -0
- data/lib/metric_fu/flog_reporter.rb +5 -0
- data/lib/tasks/churn.rake +3 -1
- data/lib/tasks/coverage.rake +35 -49
- data/lib/tasks/flay.rake +4 -1
- data/lib/tasks/flog.rake +10 -10
- data/lib/tasks/metric_fu.rake +4 -8
- data/lib/tasks/metric_fu.rb +1 -1
- data/lib/tasks/saikuro.rake +1 -1
- data/lib/tasks/stats.rake +1 -1
- data/lib/templates/churn.css +38 -0
- data/lib/templates/churn.html.erb +3 -6
- data/lib/templates/flay.css +38 -0
- data/lib/templates/flay.html.erb +10 -17
- data/lib/templates/flog.css +39 -0
- data/lib/templates/flog.html.erb +14 -19
- data/lib/templates/flog_page.html.erb +3 -15
- data/spec/base_spec.rb +8 -30
- data/spec/churn_spec.rb +3 -10
- data/spec/{flay_spec.rb → flay_reporter_spec.rb} +2 -9
- data/spec/flog_reporter/base_spec.rb +69 -0
- data/spec/md5_tracker_spec.rb +3 -1
- data/spec/spec_helper.rb +3 -7
- metadata +17 -41
- data/Manifest.txt +0 -25
- data/lib/metric_fu/flay.rb +0 -17
- data/lib/metric_fu/flog.rb +0 -139
- data/lib/metric_fu/reek.rb +0 -17
- data/lib/metric_fu/roodi.rb +0 -17
- data/lib/tasks/railroad.rake +0 -36
- data/lib/tasks/reek.rake +0 -6
- data/lib/tasks/roodi.rake +0 -7
- data/lib/templates/default.css +0 -45
- data/lib/templates/reek.html.erb +0 -30
- data/lib/templates/roodi.html.erb +0 -26
- data/spec/config_spec.rb +0 -110
- data/spec/flog_spec.rb +0 -147
- data/spec/reek_spec.rb +0 -26
data/lib/metric_fu/flog.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
module MetricFu
|
2
|
-
|
3
|
-
def self.generate_flog_report
|
4
|
-
Flog::Generator.generate_report
|
5
|
-
system("open #{Flog::Generator.metric_dir}/index.html") if open_in_browser?
|
6
|
-
end
|
7
|
-
|
8
|
-
module Flog
|
9
|
-
class Generator < Base::Generator
|
10
|
-
def generate_report
|
11
|
-
@base_dir = self.class.metric_dir
|
12
|
-
pages = []
|
13
|
-
flog_results.each do |filename|
|
14
|
-
page = Base.parse(open(filename, "r") { |f| f.read })
|
15
|
-
if page
|
16
|
-
page.filename = filename
|
17
|
-
pages << page
|
18
|
-
end
|
19
|
-
end
|
20
|
-
generate_pages(pages)
|
21
|
-
end
|
22
|
-
|
23
|
-
def generate_pages(pages)
|
24
|
-
pages.each do |page|
|
25
|
-
unless MetricFu::MD5Tracker.file_already_counted?(page.filename)
|
26
|
-
generate_page(page)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
save_html(ERB.new(File.read(template_file)).result(binding))
|
30
|
-
end
|
31
|
-
|
32
|
-
def generate_page(page)
|
33
|
-
save_html(page.to_html, page.path)
|
34
|
-
end
|
35
|
-
|
36
|
-
def flog_results
|
37
|
-
Dir.glob("#{@base_dir}/**/*.txt")
|
38
|
-
end
|
39
|
-
|
40
|
-
def template_name
|
41
|
-
"flog"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
SCORE_FORMAT = "%0.2f"
|
46
|
-
|
47
|
-
class Base
|
48
|
-
MODULE_NAME = "([A-Za-z]+)+"
|
49
|
-
METHOD_NAME = "#([a-z0-9]+_?)+\\??\\!?"
|
50
|
-
SCORE = "\\d+\\.\\d+"
|
51
|
-
|
52
|
-
METHOD_NAME_RE = Regexp.new("#{MODULE_NAME}#{METHOD_NAME}")
|
53
|
-
SCORE_RE = Regexp.new(SCORE)
|
54
|
-
|
55
|
-
METHOD_LINE_RE = Regexp.new("#{MODULE_NAME}#{METHOD_NAME}:\\s\\(#{SCORE}\\)")
|
56
|
-
OPERATOR_LINE_RE = Regexp.new("\\s+(#{SCORE}):\\s(.*)$")
|
57
|
-
|
58
|
-
class << self
|
59
|
-
|
60
|
-
def parse(text)
|
61
|
-
score = text[/\w+ = (\d+\.\d+)/, 1]
|
62
|
-
return nil unless score
|
63
|
-
page = Page.new(score)
|
64
|
-
|
65
|
-
text.each_line do |method_line|
|
66
|
-
if METHOD_LINE_RE =~ method_line and
|
67
|
-
method_name = method_line[METHOD_NAME_RE] and
|
68
|
-
score = method_line[SCORE_RE]
|
69
|
-
page.scanned_methods << ScannedMethod.new(method_name, score)
|
70
|
-
end
|
71
|
-
|
72
|
-
if OPERATOR_LINE_RE =~ method_line and
|
73
|
-
operator = method_line[OPERATOR_LINE_RE, 2] and
|
74
|
-
score = method_line[SCORE_RE]
|
75
|
-
return if page.scanned_methods.empty?
|
76
|
-
page.scanned_methods.last.operators << Operator.new(score, operator)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
page
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class Page < MetricFu::Base::Generator
|
85
|
-
attr_accessor :filename, :score, :scanned_methods
|
86
|
-
|
87
|
-
def initialize(score, scanned_methods = [])
|
88
|
-
@score = score.to_f
|
89
|
-
@scanned_methods = scanned_methods
|
90
|
-
end
|
91
|
-
|
92
|
-
def path
|
93
|
-
@path ||= File.basename(filename, ".txt") + '.html'
|
94
|
-
end
|
95
|
-
|
96
|
-
def to_html
|
97
|
-
ERB.new(File.read(template_file)).result(binding)
|
98
|
-
end
|
99
|
-
|
100
|
-
def average_score
|
101
|
-
return 0 if scanned_methods.length == 0
|
102
|
-
sum = 0
|
103
|
-
scanned_methods.each do |m|
|
104
|
-
sum += m.score
|
105
|
-
end
|
106
|
-
sum / scanned_methods.length
|
107
|
-
end
|
108
|
-
|
109
|
-
def highest_score
|
110
|
-
scanned_methods.inject(0) do |highest, m|
|
111
|
-
m.score > highest ? m.score : highest
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def template_name
|
116
|
-
'flog_page'
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
class Operator
|
121
|
-
attr_accessor :score, :operator
|
122
|
-
|
123
|
-
def initialize(score, operator)
|
124
|
-
@score = score.to_f
|
125
|
-
@operator = operator
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
class ScannedMethod
|
130
|
-
attr_accessor :name, :score, :operators
|
131
|
-
|
132
|
-
def initialize(name, score, operators = [])
|
133
|
-
@name = name
|
134
|
-
@score = score.to_f
|
135
|
-
@operators = operators
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
data/lib/metric_fu/reek.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module MetricFu
|
2
|
-
|
3
|
-
def self.generate_reek_report
|
4
|
-
Reek.generate_report
|
5
|
-
system("open #{Reek.metric_dir}/index.html") if open_in_browser?
|
6
|
-
end
|
7
|
-
|
8
|
-
class Reek < Base::Generator
|
9
|
-
|
10
|
-
def analyze
|
11
|
-
files_to_reek = MetricFu.reek[:dirs_to_reek].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
12
|
-
output = `reek #{files_to_reek.join(" ")}`
|
13
|
-
@matches = output.chomp.split("\n\n").map{|m| m.split("\n") }
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
data/lib/metric_fu/roodi.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module MetricFu
|
2
|
-
|
3
|
-
def self.generate_roodi_report
|
4
|
-
MetricFu::Roodi.generate_report
|
5
|
-
system("open #{Roodi.metric_dir}/index.html") if open_in_browser?
|
6
|
-
end
|
7
|
-
|
8
|
-
class Roodi < Base::Generator
|
9
|
-
|
10
|
-
def analyze
|
11
|
-
files_to_analyze = MetricFu.roodi[:dirs_to_roodi].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
12
|
-
output = `roodi #{files_to_analyze.join(" ")}`
|
13
|
-
@matches = output.chomp.split("\n").map{|m| m.split(" - ") }
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
data/lib/tasks/railroad.rake
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
namespace :metrics do
|
2
|
-
|
3
|
-
RAILROAD_DIR = File.join(MetricFu::BASE_DIRECTORY, 'railroad')
|
4
|
-
RAILROAD_INDEX = File.join(RAILROAD_DIR, 'index.html')
|
5
|
-
|
6
|
-
task :railroad => ['railroad:all'] do
|
7
|
-
end
|
8
|
-
|
9
|
-
namespace :railroad do
|
10
|
-
|
11
|
-
desc "Create all railroad reports"
|
12
|
-
task :all => [:models, :controllers, :aasm] do
|
13
|
-
#system("open #{RAILROAD_INDEX}") if PLATFORM['darwin']
|
14
|
-
end
|
15
|
-
|
16
|
-
desc "Create a railroad models report"
|
17
|
-
task :models do
|
18
|
-
mkdir_p(RAILROAD_DIR) unless File.directory?(RAILROAD_DIR)
|
19
|
-
`railroad -M -a -m -l -v | neato -Tpng > #{File.join(RAILROAD_DIR,'models.png')}`
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "Create a railroad controllers report"
|
23
|
-
task :controllers do
|
24
|
-
mkdir_p(RAILROAD_DIR) unless File.directory?(RAILROAD_DIR)
|
25
|
-
`railroad -C -l -v | neato -Tpng > #{File.join(RAILROAD_DIR,'controllers.png')}`
|
26
|
-
end
|
27
|
-
|
28
|
-
desc "Create a railroad acts_as_state_machine report"
|
29
|
-
task :aasm do
|
30
|
-
mkdir_p(RAILROAD_DIR) unless File.directory?(RAILROAD_DIR)
|
31
|
-
`railroad -A -l -v | neato -Tpng > #{File.join(RAILROAD_DIR,'aasm.png')}`
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
data/lib/tasks/reek.rake
DELETED
data/lib/tasks/roodi.rake
DELETED
data/lib/templates/default.css
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
body {
|
2
|
-
background-color: #efefef;
|
3
|
-
margin: 20px;
|
4
|
-
padding: 0;
|
5
|
-
font: 12px verdana, arial, helvetica;
|
6
|
-
}
|
7
|
-
|
8
|
-
table {
|
9
|
-
border-collapse: collapse;
|
10
|
-
border: 1px solid #666;
|
11
|
-
background: #fff;
|
12
|
-
margin-bottom: 20px;
|
13
|
-
}
|
14
|
-
|
15
|
-
table tr.light {
|
16
|
-
background: #fff;
|
17
|
-
}
|
18
|
-
|
19
|
-
table tr.dark {
|
20
|
-
background: #f9f9f9;
|
21
|
-
}
|
22
|
-
|
23
|
-
table td, table th {
|
24
|
-
padding: 4px 10px;
|
25
|
-
font-size: 13px;
|
26
|
-
}
|
27
|
-
table th {
|
28
|
-
text-align: center;
|
29
|
-
color: #fc0;
|
30
|
-
background: #336;
|
31
|
-
font-weight: bold;
|
32
|
-
border: #d0d0d0 1px solid;
|
33
|
-
}
|
34
|
-
|
35
|
-
table td {
|
36
|
-
border: #d0d0d0 1px solid;
|
37
|
-
}
|
38
|
-
|
39
|
-
table td.score {
|
40
|
-
text-align: right;
|
41
|
-
}
|
42
|
-
|
43
|
-
.warning {
|
44
|
-
background: yellow;
|
45
|
-
}
|
data/lib/templates/reek.html.erb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
<html>
|
2
|
-
<head>
|
3
|
-
<title>Reek Results</title>
|
4
|
-
<style>
|
5
|
-
<%= inline_css("default.css") %>
|
6
|
-
</style>
|
7
|
-
</head>
|
8
|
-
|
9
|
-
<body>
|
10
|
-
<h1>Reek Results</h1>
|
11
|
-
<p><a href="http://reek.rubyforge.org/">Reek</a> detects common code smells in ruby code.</p>
|
12
|
-
<table>
|
13
|
-
<tr>
|
14
|
-
<th>File Path</th>
|
15
|
-
<th>Code Smell</th>
|
16
|
-
</tr>
|
17
|
-
<% @matches.each_with_index do |match, count| %>
|
18
|
-
<tr class='<%= cycle("light", "dark", count) %>'>
|
19
|
-
<td><%= match.first %></td>
|
20
|
-
<td>
|
21
|
-
<% match[1..-1].each do |line| %>
|
22
|
-
<%= line %><br>
|
23
|
-
<% end %>
|
24
|
-
</td>
|
25
|
-
</tr>
|
26
|
-
<% end %>
|
27
|
-
</table>
|
28
|
-
<p>Generated on <%= Time.now.localtime %></p>
|
29
|
-
</body>
|
30
|
-
</html>
|
@@ -1,26 +0,0 @@
|
|
1
|
-
<html>
|
2
|
-
<head>
|
3
|
-
<title>Roodi Results</title>
|
4
|
-
<style>
|
5
|
-
<%= inline_css("default.css") %>
|
6
|
-
</style>
|
7
|
-
</head>
|
8
|
-
|
9
|
-
<body>
|
10
|
-
<h1>Roodi Results</h1>
|
11
|
-
<p><a href="http://roodi.rubyforge.org/">Roodi</a> parses your Ruby code and warns you about design issues you have based on the checks that is has configured.</p>
|
12
|
-
<table>
|
13
|
-
<tr>
|
14
|
-
<th>File Path</th>
|
15
|
-
<th>Warning</th>
|
16
|
-
</tr>
|
17
|
-
<% @matches.each_with_index do |match, count| %>
|
18
|
-
<tr class='<%= cycle("light", "dark", count) %>'>
|
19
|
-
<td><%= link_to_filename(match.first.split(':').first) if match.first %></td>
|
20
|
-
<td><%= match[1] %></td>
|
21
|
-
</tr>
|
22
|
-
<% end %>
|
23
|
-
</table>
|
24
|
-
<p>Generated on <%= Time.now.localtime %></p>
|
25
|
-
</body>
|
26
|
-
</html>
|
data/spec/config_spec.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
describe MetricFu::Configuration do
|
4
|
-
before do
|
5
|
-
MetricFu.configuration.reset
|
6
|
-
end
|
7
|
-
after do
|
8
|
-
ENV['CC_BUILD_ARTIFACTS'] = nil
|
9
|
-
end
|
10
|
-
describe "open_in_browser" do
|
11
|
-
it "should return false if running in cruise" do
|
12
|
-
unless ENV['CC_BUILD_ARTIFACTS']
|
13
|
-
MetricFu.open_in_browser?.should == !!PLATFORM['darwin']
|
14
|
-
ENV['CC_BUILD_ARTIFACTS'] = ''
|
15
|
-
MetricFu.open_in_browser?.should == false
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "metrics" do
|
21
|
-
it "should be configurable" do
|
22
|
-
MetricFu.metrics.should == [:coverage, :churn, :flog, :flay, :reek, :roodi, :saikuro]
|
23
|
-
MetricFu::Configuration.run do |config|
|
24
|
-
config.metrics = [:coverage, :flog]
|
25
|
-
end
|
26
|
-
MetricFu.metrics.should == [:coverage, :flog]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "churn" do
|
31
|
-
it "should be configurable" do
|
32
|
-
now = Time.now
|
33
|
-
MetricFu.churn.should == {}
|
34
|
-
MetricFu::Configuration.run do |config|
|
35
|
-
config.churn[:start_date] = now
|
36
|
-
end
|
37
|
-
MetricFu.churn.should == {:start_date => now }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "coverage" do
|
42
|
-
it "should be configurable" do
|
43
|
-
MetricFu.coverage[:test_files].should == ['test/**/*_test.rb', 'spec/**/*_spec.rb']
|
44
|
-
MetricFu::Configuration.run do |config|
|
45
|
-
config.coverage[:test_files] = ['test/**/test_*.rb']
|
46
|
-
end
|
47
|
-
MetricFu.coverage[:test_files].should == ['test/**/test_*.rb']
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "flay" do
|
52
|
-
it "should be configurable" do
|
53
|
-
now = Time.now
|
54
|
-
MetricFu.flay.should == { :dirs_to_flay => ['lib'] }
|
55
|
-
MetricFu::Configuration.run do |config|
|
56
|
-
config.flay[:dirs_to_flay] = ['cms/app', 'cms/lib']
|
57
|
-
end
|
58
|
-
MetricFu.flay.should == { :dirs_to_flay => ['cms/app', 'cms/lib'] }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "flog" do
|
63
|
-
it "should be configurable" do
|
64
|
-
MetricFu.flog.should == { :dirs_to_flog => ['lib'] }
|
65
|
-
MetricFu::Configuration.run do |config|
|
66
|
-
config.flog[:dirs_to_flog] = ['cms/app', 'cms/lib']
|
67
|
-
end
|
68
|
-
MetricFu.flog.should == { :dirs_to_flog => ['cms/app', 'cms/lib'] }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "saikuro" do
|
73
|
-
it "should be configurable" do
|
74
|
-
MetricFu.saikuro.should == {}
|
75
|
-
MetricFu::Configuration.run do |config|
|
76
|
-
config.saikuro = { "--warn_cyclo" => "3", "--error_cyclo" => "4" }
|
77
|
-
end
|
78
|
-
MetricFu.saikuro.should == { "--warn_cyclo" => "3", "--error_cyclo" => "4" }
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should only accept a Hash" do
|
82
|
-
MetricFu.saikuro.should == {}
|
83
|
-
lambda {
|
84
|
-
MetricFu::Configuration.run do |config|
|
85
|
-
config.saikuro = ''
|
86
|
-
end
|
87
|
-
}.should raise_error
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "reek" do
|
92
|
-
it "should be configurable" do
|
93
|
-
MetricFu.reek.should == { :dirs_to_reek => ['lib'] }
|
94
|
-
MetricFu::Configuration.run do |config|
|
95
|
-
config.reek[:dirs_to_reek] = ['cms/app', 'cms/lib']
|
96
|
-
end
|
97
|
-
MetricFu.reek.should == { :dirs_to_reek => ['cms/app', 'cms/lib'] }
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "roodi" do
|
102
|
-
it "should be configurable" do
|
103
|
-
MetricFu.roodi.should == { :dirs_to_roodi => ['lib'] }
|
104
|
-
MetricFu::Configuration.run do |config|
|
105
|
-
config.roodi[:dirs_to_roodi] = ['cms/app', 'cms/lib']
|
106
|
-
end
|
107
|
-
MetricFu.roodi.should == { :dirs_to_roodi => ['cms/app', 'cms/lib'] }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|