metric_adapter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/annotate.rb +1 -1
- data/examples/report.rb +3 -3
- data/lib/metric.rb +13 -2
- data/test/flay_adapter_test.rb +2 -3
- data/test/flog_adapter_test.rb +2 -3
- data/test/reek_adapter_test.rb +2 -3
- metadata +3 -3
data/examples/annotate.rb
CHANGED
@@ -67,7 +67,7 @@ end
|
|
67
67
|
# Combine metrics from all our sources (See AnalyzerMixin):
|
68
68
|
metrics = flay(files, 16) + flog(files) + reek(files)
|
69
69
|
|
70
|
-
metrics_by_path = metrics.group_by{|m| m.
|
70
|
+
metrics_by_path = metrics.group_by{|m| m.path }
|
71
71
|
|
72
72
|
files.each do |path|
|
73
73
|
metrics = metrics_by_path[path]
|
data/examples/report.rb
CHANGED
@@ -22,7 +22,7 @@ end
|
|
22
22
|
metrics = flay(files) + flog(files) + reek(files)
|
23
23
|
|
24
24
|
# Group those metrics by path
|
25
|
-
metrics_by_path = metrics.group_by{|m| m.
|
25
|
+
metrics_by_path = metrics.group_by{|m| m.path }
|
26
26
|
|
27
27
|
# For each path, print out a little report.
|
28
28
|
metrics_by_path.each do |path, metrics|
|
@@ -31,7 +31,7 @@ metrics_by_path.each do |path, metrics|
|
|
31
31
|
puts divider
|
32
32
|
|
33
33
|
puts " line: message"
|
34
|
-
metrics.sort_by{|m| m.
|
35
|
-
puts "%6d: %s" % [m.
|
34
|
+
metrics.sort_by{|m| m.line }.each do |m|
|
35
|
+
puts "%6d: %s" % [m.line, m.message]
|
36
36
|
end
|
37
37
|
end
|
data/lib/metric.rb
CHANGED
@@ -3,7 +3,7 @@ module MetricAdapter
|
|
3
3
|
# A normalized representation of a code metric.
|
4
4
|
class Metric
|
5
5
|
|
6
|
-
# Location where this metric applies
|
6
|
+
# Location where this metric applies (see the Location class)
|
7
7
|
attr_accessor :location
|
8
8
|
|
9
9
|
# Associated class and method signature
|
@@ -24,6 +24,17 @@ module MetricAdapter
|
|
24
24
|
@message = message
|
25
25
|
@score = 0
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
|
+
# Returns the path that this metric applies to, for example:
|
29
|
+
# ./lib/metric.rb
|
30
|
+
def path
|
31
|
+
location.path
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the line number this metric applies to.
|
35
|
+
def line
|
36
|
+
location.line
|
37
|
+
end
|
38
|
+
|
28
39
|
end
|
29
40
|
end
|
data/test/flay_adapter_test.rb
CHANGED
@@ -25,10 +25,9 @@ class FlayAdapterTest < MiniTest::Unit::TestCase
|
|
25
25
|
def test_flay_adapts_locations
|
26
26
|
adapter = flay_self
|
27
27
|
metric = adapter.metrics.first
|
28
|
-
location = metric.location
|
29
28
|
|
30
|
-
assert_equal __FILE__,
|
31
|
-
assert
|
29
|
+
assert_equal __FILE__, metric.path, "Should reference this file"
|
30
|
+
assert metric.line != 0, "Line numbers should be captured (line:0 should not show up in flog)"
|
32
31
|
end
|
33
32
|
|
34
33
|
def test_flay_messages
|
data/test/flog_adapter_test.rb
CHANGED
@@ -16,10 +16,9 @@ class FlogAdapterTest < MiniTest::Unit::TestCase
|
|
16
16
|
def test_flogging_adapts_locations
|
17
17
|
adapter = flog_self
|
18
18
|
metric = adapter.metrics.first
|
19
|
-
location = metric.location
|
20
19
|
|
21
|
-
assert_equal __FILE__,
|
22
|
-
assert
|
20
|
+
assert_equal __FILE__, metric.path, "Should reference this file"
|
21
|
+
assert metric.line != 0, "Line numbers should be captured (line:0 should not show up in flog)"
|
23
22
|
end
|
24
23
|
|
25
24
|
def test_flogging_messages
|
data/test/reek_adapter_test.rb
CHANGED
@@ -18,10 +18,9 @@ class ReekAdapterTest < MiniTest::Unit::TestCase
|
|
18
18
|
def test_examiner_adapts_locations
|
19
19
|
adapter = examine_sample
|
20
20
|
metric = adapter.metrics.first
|
21
|
-
location = metric.location
|
22
21
|
|
23
|
-
assert_equal SAMPLE_PATH,
|
24
|
-
assert
|
22
|
+
assert_equal SAMPLE_PATH, metric.path, "Should have included the path"
|
23
|
+
assert metric.line > 0, "Should have a non zero line number"
|
25
24
|
end
|
26
25
|
|
27
26
|
def test_examiner_returns_metrics_for_each_line_of_each_smell
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Adam Sanderson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2013-06-
|
17
|
+
date: 2013-06-26 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|