p8-metric_fu 0.8.4.9 → 0.8.4.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README +34 -13
- data/lib/metric_fu/base.rb +58 -9
- data/lib/metric_fu/churn.rb +3 -3
- data/lib/metric_fu/flay.rb +1 -1
- data/lib/tasks/coverage.rake +1 -1
- data/lib/tasks/flog.rake +1 -1
- data/spec/base_spec.rb +1 -6
- metadata +1 -1
data/README
CHANGED
@@ -47,31 +47,56 @@ project.scheduler.polling_interval = 24.hours
|
|
47
47
|
|
48
48
|
Which will check for updates every 24 hours and run all the metrics rake tasks (migrating your test db first). The output will be visible from an individual build's detail page.
|
49
49
|
|
50
|
+
****Notes on configuration****
|
51
|
+
|
52
|
+
MetricFu::Configuration.run do |config|
|
53
|
+
config.open_in_browser = false # Don't open reports in the browser on a mac
|
54
|
+
config.churn_options = { :start_date => lambda{ 3.months.ago } }
|
55
|
+
config.coverage_options = { :test_files => ['test/**/test_*.rb'] }
|
56
|
+
config.flog_options = { :dirs_to_flog => ['cms/app', 'cms/lib'] }
|
57
|
+
config.flay_options = { :dirs_to_flay => ['cms/app', 'cms/lib'] }
|
58
|
+
config.saikuro_options = { "--warn_cyclo" => "3", "--error_cyclo" => "4" }
|
59
|
+
config.open_in_browser = false # Don't open reports in the browser on a mac
|
60
|
+
...
|
61
|
+
end
|
50
62
|
|
51
63
|
****Notes on metrics:coverage****
|
52
64
|
|
53
65
|
When creating a coverage report, metric_fu runs all the tests in the test folder and specs in spec folder using Rcov.
|
66
|
+
You can configure the coverage test files pattern:
|
67
|
+
config.coverage_test_files = ['test/**/test_*.rb']
|
68
|
+
|
69
|
+
The default value is ['test/**/*_test.rb', 'spec/**/*_spec.rb']
|
54
70
|
|
55
71
|
|
56
72
|
****Notes on metrics:saikuro****
|
57
73
|
|
58
74
|
Saikuro is bundled with metric_fu so you don't have to install it. Look at the SAIKURO_README (or the internet) for more documentation on Saikuro. If you wish to change the options Saikuro is run with, then set this constant in your Rakefile:
|
59
|
-
|
60
|
-
MetricFu::SAIKURO_OPTIONS = { "--warn_cyclo" => "3", "--error_cyclo" => "4" }
|
61
75
|
|
62
|
-
|
76
|
+
config.saikuro_options = { "--warn_cyclo" => "3", "--error_cyclo" => "4" }
|
77
|
+
|
78
|
+
saikuro_options is a hash that gets merged with the default options hash. The above example will set the warn_cyclo to 3 and the error_cyclo to 4 (which is way too low -- it's just an example) instructing Saikuro to flag methods with a higher cyclomatic complexity in it's report.
|
63
79
|
|
64
80
|
If you want to have Saikuro look at multiple folders you can put something like this in your rakefile:
|
65
|
-
MetricFu::SAIKURO_OPTIONS = {"--input_directory" => '"cms/app | cms/lib"'}
|
66
81
|
|
82
|
+
config.saikuro_options = {"--input_directory" => '"cms/app | cms/lib"'}
|
67
83
|
|
68
|
-
|
84
|
+
|
85
|
+
****Notes on metrics:flay****
|
69
86
|
|
70
87
|
Flog is another way of measuring complexity (or tortured code as the Flog authors like to put it). You should check out the awesome, and a little scary, Flog website for more info.
|
71
88
|
|
72
|
-
'rake metrics:flog:custom' allows you to specify a custom set of directories to
|
89
|
+
'rake metrics:flog:custom' allows you to specify a custom set of directories to Flay (in your rakefile) like so:
|
90
|
+
|
91
|
+
config.flay_options[:dirs_to_flay] = ['cms/app', 'cms/lib']
|
73
92
|
|
74
|
-
|
93
|
+
****Notes on metrics:flog****
|
94
|
+
|
95
|
+
Flog is another way of measuring complexity (or tortured code as the Flog authors like to put it). You should check out the awesome, and a little scary, Flog website for more info.
|
96
|
+
|
97
|
+
'rake metrics:flog:custom' allows you to specify a custom set of directories to Flog (in your rakefile) like so:
|
98
|
+
|
99
|
+
config.flog_options[:dirs_to_flog] = ['cms/app', 'cms/lib']
|
75
100
|
|
76
101
|
|
77
102
|
****Notes on metrics:stats****
|
@@ -83,17 +108,13 @@ This is just 'rake stats' for Rails put into a file. On my projects I like to b
|
|
83
108
|
|
84
109
|
Files that change a lot in your project may be bad a sign. This task uses "svn log" to identify those files and put them in a report. The default is to start counting changes from the beginning of your project, which might be too far back so you can change like so:
|
85
110
|
|
86
|
-
|
111
|
+
config.churn_options = { :start_date => lambda{ 3.months.ago } }
|
87
112
|
|
88
113
|
The Proc is there because '3.months.ago' only works when after the Rails Environment is loaded (and Rails extends Fixnum) which I didn't want to do every time you run a rake task.
|
89
114
|
|
90
115
|
You can also change the minimum churn count like so:
|
91
116
|
|
92
|
-
|
93
|
-
|
94
|
-
If you use git, then tell churn about it:
|
95
|
-
|
96
|
-
MetricFu::CHURN_OPTIONS = {:scm => :git}
|
117
|
+
config.churn_options = { :minimum_churn_count => 3 }
|
97
118
|
|
98
119
|
|
99
120
|
****Thanks****
|
data/lib/metric_fu/base.rb
CHANGED
@@ -9,15 +9,7 @@ module MetricFu
|
|
9
9
|
CODE_DIRS = ['app', 'lib']
|
10
10
|
else
|
11
11
|
CODE_DIRS = ['lib']
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.open_in_browser?
|
15
|
-
if defined?(MetricFu::OPEN_IN_BROWSER)
|
16
|
-
PLATFORM['darwin'] && MetricFu::OPEN_IN_BROWSER
|
17
|
-
else
|
18
|
-
PLATFORM['darwin']
|
19
|
-
end
|
20
|
-
end
|
12
|
+
end
|
21
13
|
|
22
14
|
module Base
|
23
15
|
|
@@ -81,4 +73,61 @@ module MetricFu
|
|
81
73
|
end
|
82
74
|
end
|
83
75
|
end
|
76
|
+
|
77
|
+
class << self
|
78
|
+
# The Configuration instance used to configure the Rails environment
|
79
|
+
def configuration
|
80
|
+
@@configuration ||= Configuration.new
|
81
|
+
end
|
82
|
+
|
83
|
+
def churn_options
|
84
|
+
configuration.churn_options
|
85
|
+
end
|
86
|
+
|
87
|
+
def coverage_options
|
88
|
+
configuration.coverage_options
|
89
|
+
end
|
90
|
+
|
91
|
+
def flay_options
|
92
|
+
configuration.flay_options
|
93
|
+
end
|
94
|
+
|
95
|
+
def flog_options
|
96
|
+
configuration.flog_options
|
97
|
+
end
|
98
|
+
|
99
|
+
def open_in_browser?
|
100
|
+
PLATFORM['darwin'] && configuration.open_in_browser
|
101
|
+
end
|
102
|
+
|
103
|
+
def saikuro_options
|
104
|
+
configuration.saikuro_options
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
class Configuration
|
110
|
+
attr_accessor :churn_options, :coverage_options, :flay_options, :flog_options, :open_in_browser, :saikuro_options
|
111
|
+
def initialize
|
112
|
+
raise "Use config.churn_options instead of MetricFu::CHURN_OPTIONS" if defined? ::MetricFu::CHURN_OPTIONS
|
113
|
+
raise "Use config.flog_options[:dirs_to_flog] instead of MetricFu::DIRECTORIES_TO_FLOG" if defined? ::MetricFu::DIRECTORIES_TO_FLOG
|
114
|
+
raise "Use config.saikuro_options instead of MetricFu::SAIKURO_OPTIONS" if defined? ::MetricFu::SAIKURO_OPTIONS
|
115
|
+
reset
|
116
|
+
end
|
117
|
+
def self.run()
|
118
|
+
yield MetricFu.configuration
|
119
|
+
end
|
120
|
+
def reset
|
121
|
+
@churn_options = {}
|
122
|
+
@coverage_options = { :test_files => ['test/**/*_test.rb', 'spec/**/*_spec.rb'] }
|
123
|
+
@flay_options = { :dirs_to_flay => CODE_DIRS}
|
124
|
+
@flog_options = { :dirs_to_flog => CODE_DIRS}
|
125
|
+
@open_in_browser = true
|
126
|
+
@saikuro_options = {}
|
127
|
+
end
|
128
|
+
def saikuro_options=(options)
|
129
|
+
raise "saikuro_options need to be a Hash" unless options.is_a?(Hash)
|
130
|
+
@saikuro_options = options
|
131
|
+
end
|
132
|
+
end
|
84
133
|
end
|
data/lib/metric_fu/churn.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
CHURN_DIR = File.join(MetricFu::BASE_DIRECTORY, 'churn')
|
2
|
-
|
3
1
|
module MetricFu
|
2
|
+
CHURN_DIR = File.join(MetricFu::BASE_DIRECTORY, 'churn')
|
3
|
+
|
4
4
|
def self.generate_churn_report
|
5
|
-
MetricFu::Churn.generate_report(CHURN_DIR,
|
5
|
+
MetricFu::Churn.generate_report(CHURN_DIR, MetricFu.churn_options )
|
6
6
|
system("open #{CHURN_DIR}/index.html") if open_in_browser?
|
7
7
|
end
|
8
8
|
|
data/lib/metric_fu/flay.rb
CHANGED
@@ -9,7 +9,7 @@ module MetricFu
|
|
9
9
|
class Flay < Base::Generator
|
10
10
|
|
11
11
|
def analyze
|
12
|
-
files_to_flay = MetricFu
|
12
|
+
files_to_flay = MetricFu.flay_options[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
|
13
13
|
output = `flay #{files_to_flay.join(" ")}`
|
14
14
|
@matches = output.chomp.split("\n\n").map{|m| m.split("\n ") }
|
15
15
|
end
|
data/lib/tasks/coverage.rake
CHANGED
@@ -20,7 +20,7 @@ begin
|
|
20
20
|
desc "RCov task to generate report"
|
21
21
|
Rcov::RcovTask.new(:do => :clean) do |t|
|
22
22
|
FileUtils.mkdir_p(MetricFu::BASE_DIRECTORY) unless File.directory?(MetricFu::BASE_DIRECTORY)
|
23
|
-
t.test_files = FileList[
|
23
|
+
t.test_files = FileList[*MetricFu.coverage_options[:test_files]]
|
24
24
|
t.rcov_opts = ["--sort coverage", "--html", "--rails", "--exclude /gems/,/Library/"]
|
25
25
|
t.output_dir = COVERAGE_DIR
|
26
26
|
# this line is a fix for Rails 2.1 relative loading issues
|
data/lib/tasks/flog.rake
CHANGED
@@ -39,7 +39,7 @@ begin
|
|
39
39
|
|
40
40
|
desc "Generate a flog report from specified directories"
|
41
41
|
task :custom do
|
42
|
-
MetricFu::
|
42
|
+
MetricFu::flog_options[:dirs_to_flog].each { |directory| flog(directory, directory) }
|
43
43
|
MetricFu.generate_flog_report
|
44
44
|
end
|
45
45
|
|
data/spec/base_spec.rb
CHANGED
@@ -47,10 +47,5 @@ describe MetricFu::Base::Generator do
|
|
47
47
|
@generator.template_name.should == 'generator'
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
51
|
-
describe "open_in_browser?" do
|
52
|
-
it "should return the value of PLATFORM['darwin']" do
|
53
|
-
@generator = MetricFu.open_in_browser?.should == PLATFORM['darwin']
|
54
|
-
end
|
55
|
-
end
|
50
|
+
|
56
51
|
end
|