edouard-metric_fu 1.0.3.5 → 1.0.3.6
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/lib/base/configuration.rb +1 -1
- data/lib/generators/saikuro.rb +55 -50
- data/lib/templates/awesome/flog.html.erb +2 -2
- data/lib/templates/awesome/layout.html.erb +1 -1
- data/lib/templates/awesome/rcov.html.erb +3 -3
- data/spec/base/configuration_spec.rb +1 -1
- data/spec/generators/saikuro_spec.rb +21 -11
- metadata +2 -1
data/lib/base/configuration.rb
CHANGED
|
@@ -122,7 +122,7 @@ module MetricFu
|
|
|
122
122
|
'..', '..')
|
|
123
123
|
@template_directory = File.join(@metric_fu_root_directory,
|
|
124
124
|
'lib', 'templates')
|
|
125
|
-
@template_class =
|
|
125
|
+
@template_class = AwesomeTemplate
|
|
126
126
|
set_metrics
|
|
127
127
|
set_code_dirs
|
|
128
128
|
@flay = { :dirs_to_flay => @code_dirs }
|
data/lib/generators/saikuro.rb
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
module MetricFu
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
class Saikuro < Generator
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
|
|
6
6
|
def emit
|
|
7
|
-
relative_path = [File.dirname(__FILE__), '..', '..',
|
|
7
|
+
relative_path = [File.dirname(__FILE__), '..', '..',
|
|
8
8
|
'vendor', 'saikuro', 'saikuro.rb']
|
|
9
9
|
saikuro = File.expand_path(File.join(relative_path))
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
format_directories
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
options_string = MetricFu.saikuro.inject("") do |options, option|
|
|
14
|
-
options + "--#{option.join(' ')} "
|
|
14
|
+
options + "--#{option.join(' ')} "
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
sh %{ruby "#{saikuro}" #{options_string}} do |ok, response|
|
|
18
18
|
unless ok
|
|
19
19
|
puts "Saikuro failed with exit status: #{response.exitstatus}"
|
|
@@ -21,20 +21,20 @@ class Saikuro < Generator
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
def format_directories
|
|
26
|
-
dirs = MetricFu.saikuro[:input_directory]
|
|
26
|
+
dirs = MetricFu.saikuro[:input_directory].join(" | ")
|
|
27
27
|
dirs = "\"#{dirs}\""
|
|
28
28
|
MetricFu.saikuro[:input_directory] = dirs
|
|
29
29
|
end
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
def analyze
|
|
32
32
|
@files = []
|
|
33
33
|
saikuro_results.each do |path|
|
|
34
34
|
if Saikuro::SFile.is_valid_text_file?(path)
|
|
35
|
-
file = Saikuro::SFile.new(path)
|
|
36
|
-
if file
|
|
37
|
-
@files << file
|
|
35
|
+
file = Saikuro::SFile.new(path)
|
|
36
|
+
if file
|
|
37
|
+
@files << file
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
end
|
|
@@ -50,51 +50,51 @@ class Saikuro < Generator
|
|
|
50
50
|
@classes = klasses.sort_by {|k| k.complexity.to_i}
|
|
51
51
|
@classes.reverse!
|
|
52
52
|
meths = []
|
|
53
|
-
@files.each {|f|
|
|
53
|
+
@files.each {|f|
|
|
54
54
|
f.elements.each {|el|
|
|
55
55
|
el.defs.each {|defn|
|
|
56
56
|
defn.name = "#{el.name}##{defn.name}"
|
|
57
|
-
meths <<
|
|
57
|
+
meths << defn}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
meths = meths.sort_by {|meth| meth.complexity.to_i}
|
|
61
61
|
@meths = meths.reverse
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
end
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
def to_h
|
|
66
66
|
files = @files.map do |file|
|
|
67
67
|
my_file = file.to_h
|
|
68
68
|
my_file[:filename] = file.filename
|
|
69
|
-
my_file
|
|
69
|
+
my_file
|
|
70
70
|
end
|
|
71
|
-
{:saikuro => {:files => files,
|
|
71
|
+
{:saikuro => {:files => files,
|
|
72
72
|
:classes => @classes.map {|c| c.to_h},
|
|
73
|
-
:methods => @meths.map {|m| m.to_h}
|
|
73
|
+
:methods => @meths.map {|m| m.to_h}
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|
|
76
76
|
end
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
def saikuro_results
|
|
79
79
|
Dir.glob("#{metric_directory}/**/*.html")
|
|
80
80
|
end
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
private
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
|
|
84
|
+
|
|
85
85
|
end
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
class Saikuro::SFile
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
attr_reader :elements
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
def initialize(path)
|
|
92
92
|
@path = path
|
|
93
93
|
@file_handle = File.open(@path, "r")
|
|
94
94
|
@elements = []
|
|
95
95
|
get_elements
|
|
96
96
|
end
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
def self.is_valid_text_file?(path)
|
|
99
99
|
File.open(path, "r") do |f|
|
|
100
100
|
unless f.readline.match /--/
|
|
@@ -104,24 +104,29 @@ class Saikuro::SFile
|
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
def filename
|
|
109
109
|
File.basename(@path, '_cyclo.html')
|
|
110
110
|
end
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
def to_h
|
|
113
113
|
merge_classes
|
|
114
114
|
{:classes => @elements}
|
|
115
115
|
end
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
def get_elements
|
|
118
118
|
begin
|
|
119
119
|
while ( line = @file_handle.readline) do
|
|
120
|
+
element ||= nil
|
|
120
121
|
if line.match /START/
|
|
122
|
+
unless element.nil?
|
|
123
|
+
@elements << element
|
|
124
|
+
element = nil
|
|
125
|
+
end
|
|
121
126
|
line = @file_handle.readline
|
|
122
127
|
element = Saikuro::ParsingElement.new(line)
|
|
123
128
|
elsif line.match /END/
|
|
124
|
-
@elements << element
|
|
129
|
+
@elements << element unless element.nil?
|
|
125
130
|
element = nil
|
|
126
131
|
else
|
|
127
132
|
element << line
|
|
@@ -131,8 +136,8 @@ class Saikuro::SFile
|
|
|
131
136
|
nil
|
|
132
137
|
end
|
|
133
138
|
end
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
|
|
140
|
+
|
|
136
141
|
def merge_classes
|
|
137
142
|
new_elements = []
|
|
138
143
|
get_class_names.each do |target_class|
|
|
@@ -145,20 +150,20 @@ class Saikuro::SFile
|
|
|
145
150
|
lines += el.lines.to_i
|
|
146
151
|
defns << el.defs
|
|
147
152
|
end
|
|
148
|
-
|
|
153
|
+
|
|
149
154
|
new_element = {:class_name => target_class,
|
|
150
155
|
:complexity => complexity,
|
|
151
|
-
:lines
|
|
156
|
+
:lines => lines,
|
|
152
157
|
:methods => defns.flatten.map {|d| d.to_h}}
|
|
153
158
|
new_element[:methods] = new_element[:methods].
|
|
154
159
|
sort_by {|x| x[:complexity] }.
|
|
155
160
|
reverse
|
|
156
|
-
|
|
161
|
+
|
|
157
162
|
new_elements << new_element
|
|
158
163
|
end
|
|
159
164
|
@elements = new_elements if new_elements
|
|
160
165
|
end
|
|
161
|
-
|
|
166
|
+
|
|
162
167
|
def get_class_names
|
|
163
168
|
class_names = []
|
|
164
169
|
@elements.each do |element|
|
|
@@ -168,31 +173,31 @@ class Saikuro::SFile
|
|
|
168
173
|
end
|
|
169
174
|
class_names
|
|
170
175
|
end
|
|
171
|
-
|
|
176
|
+
|
|
172
177
|
end
|
|
173
|
-
|
|
178
|
+
|
|
174
179
|
class Saikuro::ParsingElement
|
|
175
180
|
TYPE_REGEX=/Type:(.*) Name/
|
|
176
181
|
NAME_REGEX=/Name:(.*) Complexity/
|
|
177
182
|
COMPLEXITY_REGEX=/Complexity:(.*) Lines/
|
|
178
183
|
LINES_REGEX=/Lines:(.*)/
|
|
179
|
-
|
|
184
|
+
|
|
180
185
|
attr_reader :complexity, :lines, :defs, :element_type
|
|
181
186
|
attr_accessor :name
|
|
182
|
-
|
|
187
|
+
|
|
183
188
|
def initialize(line)
|
|
184
189
|
@line = line
|
|
185
190
|
@element_type = line.match(TYPE_REGEX)[1].strip
|
|
186
191
|
@name = line.match(NAME_REGEX)[1].strip
|
|
187
|
-
@complexity
|
|
192
|
+
@complexity = line.match(COMPLEXITY_REGEX)[1].strip
|
|
188
193
|
@lines = line.match(LINES_REGEX)[1].strip
|
|
189
194
|
@defs = []
|
|
190
195
|
end
|
|
191
|
-
|
|
196
|
+
|
|
192
197
|
def <<(line)
|
|
193
|
-
@defs << Saikuro::ParsingElement.new(line)
|
|
198
|
+
@defs << Saikuro::ParsingElement.new(line)
|
|
194
199
|
end
|
|
195
|
-
|
|
200
|
+
|
|
196
201
|
def to_h
|
|
197
202
|
base = {:name => @name, :complexity => @complexity.to_i, :lines => @lines.to_i}
|
|
198
203
|
unless @defs.empty?
|
|
@@ -206,6 +211,6 @@ class Saikuro::ParsingElement
|
|
|
206
211
|
return base
|
|
207
212
|
end
|
|
208
213
|
end
|
|
209
|
-
|
|
210
|
-
|
|
214
|
+
|
|
215
|
+
|
|
211
216
|
end
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
</tr>
|
|
13
13
|
<% @flog[:pages].each do |page| %>
|
|
14
14
|
<tr>
|
|
15
|
-
<td><%= page[:path] %></td>
|
|
15
|
+
<td><a href="#<%= page[:path].gsub(/[^a-z]+/, '_') %>"><%= page[:path] %></a></td>
|
|
16
16
|
<td><%= page[:score].round %></td>
|
|
17
17
|
<td><%= page[:scanned_methods].length %></td>
|
|
18
18
|
<td><%= page[:average_score].round %></td>
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
</table>
|
|
23
23
|
|
|
24
24
|
<% @flog[:pages].each do |page| %>
|
|
25
|
-
<h2><%= page[:path] %></h2>
|
|
25
|
+
<h2 id="<%= page[:path].gsub(/[^a-z]+/, '_') %>"><%= page[:path] %></h2>
|
|
26
26
|
<% page[:scanned_methods].each do |sm| %>
|
|
27
27
|
<p><%= sm[:name] %></p>
|
|
28
28
|
<table>
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id='header'>
|
|
17
|
-
<h1><a href="/">metrics</a> |
|
|
17
|
+
<h1><a href="/">metrics</a> | <a href="index.html"><%= @name %></a></h1>
|
|
18
18
|
<address class='watermark'>
|
|
19
19
|
built with
|
|
20
20
|
<a href='http://metric-fu.rubyforge.org/'>metric-fu</a>
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
<% count = 0 %>
|
|
10
10
|
<% @rcov.each_pair do |fname, file| %>
|
|
11
11
|
<tr>
|
|
12
|
-
<td><%= fname %></td>
|
|
12
|
+
<td><a href="#<%= fname.gsub(/[^a-z]+/, '_') %>"><%= fname %></a></td>
|
|
13
13
|
<td><%= file[:percent_run] %></td>
|
|
14
14
|
</tr>
|
|
15
15
|
<% count += 1 %>
|
|
16
16
|
<% end %>
|
|
17
17
|
</table>
|
|
18
18
|
|
|
19
|
-
<% @rcov.each_pair do |fname, file| %>
|
|
20
|
-
<h2> <%= fname %></h2>
|
|
19
|
+
<% @rcov.sort_by{|k,v| v[:percent_run]}.each_pair do |fname, file| %>
|
|
20
|
+
<h2 id="<%= fname.gsub(/[^a-z]+/, '_') %>"> <%= fname %></h2>
|
|
21
21
|
<div class="rcov_overflow">
|
|
22
22
|
<table class="rcov_code">
|
|
23
23
|
<% file[:lines].each do |line| %>
|
|
@@ -129,7 +129,7 @@ describe MetricFu::Configuration do
|
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
it 'should set @template_class to StandardTemplate' do
|
|
132
|
-
template_class.should ==
|
|
132
|
+
template_class.should == AwesomeTemplate
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
it 'should set @flay to {:dirs_to_flay => @code_dirs}' do
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
describe Saikuro do
|
|
4
4
|
describe "to_h method" do
|
|
5
5
|
before :all do
|
|
@@ -10,44 +10,54 @@ describe Saikuro do
|
|
|
10
10
|
saikuro.analyze
|
|
11
11
|
@output = saikuro.to_h
|
|
12
12
|
end
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
it "should find the filename of a file" do
|
|
15
15
|
@output[:saikuro][:files].first[:filename].should == 'users_controller.rb'
|
|
16
16
|
end
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
it "should find the name of the classes" do
|
|
19
19
|
@output[:saikuro][:classes].first[:name].should == "UsersController"
|
|
20
20
|
@output[:saikuro][:classes][1][:name].should == "SessionsController"
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
it "should put the most complex method first" do
|
|
24
24
|
@output[:saikuro][:methods].first[:name].should == "UsersController#create"
|
|
25
25
|
@output[:saikuro][:methods].first[:complexity].should == 4
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
it "should find the complexity of a method" do
|
|
29
29
|
@output[:saikuro][:methods].first[:complexity].should == 4
|
|
30
30
|
end
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
it "should find the lines of a method" do
|
|
33
33
|
@output[:saikuro][:methods].first[:lines].should == 15
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
describe "emit method" do
|
|
38
38
|
it "should format the directories" do
|
|
39
39
|
MetricFu::Configuration.run {}
|
|
40
40
|
File.stub!(:directory?).and_return(true)
|
|
41
41
|
saikuro = MetricFu::Saikuro.new
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
MetricFu.saikuro[:input_directory] = ["app", "lib"]
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
File.stub!(:dirname).and_return('..')
|
|
46
46
|
File.stub!(:expand_path)
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
saikuro.should_receive(:sh).with(/"app \| lib"/)
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
saikuro.emit
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
|
+
|
|
54
|
+
describe Saikuro::SFile do
|
|
55
|
+
describe "getting elements from a Saikuro result file" do
|
|
56
|
+
it "should parse nested START/END sections" do
|
|
57
|
+
path = File.join(File.dirname(__FILE__), "..", "resources", "saikuro_sfiles", "thing.rb_cyclo.html")
|
|
58
|
+
sfile = Saikuro::SFile.new path
|
|
59
|
+
sfile.elements.map { |e| e.complexity }.sort.should eql(["0","0","2"])
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
53
63
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: edouard-metric_fu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.3.
|
|
4
|
+
version: 1.0.3.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jake Scruggs
|
|
@@ -10,6 +10,7 @@ authors:
|
|
|
10
10
|
- Petrik de Heus
|
|
11
11
|
- Grant McInnes
|
|
12
12
|
- Nick Quaranto
|
|
13
|
+
- "\xC3\x89douard Bri\xC3\xA8re"
|
|
13
14
|
autorequire:
|
|
14
15
|
bindir: bin
|
|
15
16
|
cert_chain: []
|