khall-metric_fu 1.0.2.1

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.
Files changed (47) hide show
  1. data/HISTORY +119 -0
  2. data/MIT-LICENSE +22 -0
  3. data/Manifest.txt +25 -0
  4. data/README +1 -0
  5. data/Rakefile +46 -0
  6. data/TODO +14 -0
  7. data/lib/base/base_template.rb +134 -0
  8. data/lib/base/configuration.rb +187 -0
  9. data/lib/base/generator.rb +147 -0
  10. data/lib/base/md5_tracker.rb +52 -0
  11. data/lib/base/report.rb +100 -0
  12. data/lib/generators/churn.rb +86 -0
  13. data/lib/generators/flay.rb +29 -0
  14. data/lib/generators/flog.rb +127 -0
  15. data/lib/generators/rcov.rb +77 -0
  16. data/lib/generators/reek.rb +32 -0
  17. data/lib/generators/roodi.rb +24 -0
  18. data/lib/generators/saikuro.rb +212 -0
  19. data/lib/generators/stats.rb +43 -0
  20. data/lib/metric_fu.rb +20 -0
  21. data/lib/templates/standard/churn.html.erb +30 -0
  22. data/lib/templates/standard/default.css +64 -0
  23. data/lib/templates/standard/flay.html.erb +33 -0
  24. data/lib/templates/standard/flog.html.erb +52 -0
  25. data/lib/templates/standard/index.html.erb +38 -0
  26. data/lib/templates/standard/rcov.html.erb +42 -0
  27. data/lib/templates/standard/reek.html.erb +41 -0
  28. data/lib/templates/standard/roodi.html.erb +28 -0
  29. data/lib/templates/standard/saikuro.html.erb +83 -0
  30. data/lib/templates/standard/standard_template.rb +26 -0
  31. data/lib/templates/standard/stats.html.erb +54 -0
  32. data/spec/base/base_template_spec.rb +140 -0
  33. data/spec/base/configuration_spec.rb +303 -0
  34. data/spec/base/generator_spec.rb +159 -0
  35. data/spec/base/md5_tracker_spec.rb +57 -0
  36. data/spec/base/report_spec.rb +139 -0
  37. data/spec/generators/churn_spec.rb +152 -0
  38. data/spec/generators/flay_spec.rb +101 -0
  39. data/spec/generators/flog_spec.rb +200 -0
  40. data/spec/generators/reek_spec.rb +59 -0
  41. data/spec/generators/saikuro_spec.rb +53 -0
  42. data/spec/generators/stats_spec.rb +74 -0
  43. data/spec/spec_helper.rb +28 -0
  44. data/tasks/metric_fu.rake +15 -0
  45. data/tasks/railroad.rake +39 -0
  46. data/vendor/saikuro/saikuro.rb +1214 -0
  47. metadata +163 -0
@@ -0,0 +1,147 @@
1
+ module MetricFu
2
+
3
+ # = Generator
4
+ #
5
+ # The Generator class is an abstract class that provides the
6
+ # skeleton for producing different types of metrics.
7
+ #
8
+ # It drives the production of the metrics through a template
9
+ # method - #generate_report(options={}). This method calls
10
+ # #emit, #analyze and #to_h in order to produce the metrics.
11
+ #
12
+ # To implement a concrete class to generate a metric, therefore,
13
+ # the class must implement those three methods.
14
+ #
15
+ # * #emit should take care of running the metric tool and
16
+ # gathering its output.
17
+ # * #analyze should take care of manipulating the output from
18
+ # #emit and making it possible to store it in a programmatic way.
19
+ # * #to_h should provide a hash representation of the output from
20
+ # #analyze ready to be serialized into yaml at some point.
21
+ #
22
+ # == Pre-conditions
23
+ #
24
+ # Based on the class name of the concrete class implementing a
25
+ # Generator, the Generator class will create a 'metric_directory'
26
+ # named after the class under the MetricFu.scratch_directory, where
27
+ # any output from the #emit method should go.
28
+ #
29
+ # It will also create the MetricFu.output_directory if neccessary, and
30
+ # in general setup the directory structure that the MetricFu system
31
+ # expects.
32
+ class Generator
33
+ attr_reader :report, :template
34
+
35
+ def initialize(options={})
36
+ create_metric_dir_if_missing
37
+ create_output_dir_if_missing
38
+ end
39
+
40
+ # Creates a new generator and returns the output of the
41
+ # #generate_report method. This is the typical way to
42
+ # generate a new MetricFu report. For more information see
43
+ # the #generate_report instance method.
44
+ #
45
+ # @params options Hash
46
+ # A currently unused hash to configure the Generator
47
+ #
48
+ # @see generate_report
49
+ def self.generate_report(options={})
50
+ generator = self.new(options)
51
+ generator.generate_report
52
+ end
53
+
54
+ # Provides the unqualified class name of an implemented concrete
55
+ # class, as a string. For example:
56
+ #
57
+ # class Flay < Generator; end
58
+ # klass = Flay.new
59
+ # klass.class_name
60
+ # > "flay"
61
+ #
62
+ # @return String
63
+ # The unqualified class name of this concrete class, returned
64
+ # as a string.
65
+ def self.class_name
66
+ self.to_s.split('::').last.downcase
67
+ end
68
+
69
+ # Returns the directory where the Generator will write any output
70
+ def self.metric_directory
71
+ File.join(MetricFu.scratch_directory, class_name)
72
+ end
73
+
74
+ def create_metric_dir_if_missing #:nodoc:
75
+ unless File.directory?(metric_directory)
76
+ FileUtils.mkdir_p(metric_directory, :verbose => false)
77
+ end
78
+ end
79
+
80
+ def create_output_dir_if_missing #:nodoc:
81
+ unless File.directory?(MetricFu.output_directory)
82
+ FileUtils.mkdir_p(MetricFu.output_directory, :verbose => false)
83
+ end
84
+ end
85
+
86
+ # @return String
87
+ # The path of the metric directory this class is using.
88
+ def metric_directory
89
+ self.class.metric_directory
90
+ end
91
+
92
+
93
+ # Defines some hook methods for the concrete classes to hook into.
94
+ %w[emit analyze].each do |meth|
95
+ define_method("before_#{meth}".to_sym) {}
96
+ define_method("after_#{meth}".to_sym) {}
97
+ end
98
+ define_method("before_to_h".to_sym) {}
99
+
100
+ # Provides a template method to drive the production of a metric
101
+ # from a concrete implementation of this class. Each concrete
102
+ # class must implement the three methods that this template method
103
+ # calls: #emit, #analyze and #to_h. For more details, see the
104
+ # class documentation.
105
+ #
106
+ # This template method also calls before_emit, after_emit... etc.
107
+ # methods to allow extra hooks into the processing methods, and help
108
+ # to keep the logic of your Generators clean.
109
+ def generate_report
110
+ %w[emit analyze].each do |meth|
111
+ send("before_#{meth}".to_sym)
112
+ send("#{meth}".to_sym)
113
+ send("after_#{meth}".to_sym)
114
+ end
115
+ before_to_h()
116
+ to_h()
117
+ end
118
+
119
+ def round_to_tenths(decimal)
120
+ (decimal * 10).round / 10.0
121
+ end
122
+
123
+ def emit #:nodoc:
124
+ raise <<-EOF
125
+ This method must be implemented by a concrete class descending
126
+ from Generator. See generator class documentation for more
127
+ information.
128
+ EOF
129
+ end
130
+
131
+ def analyze #:nodoc:
132
+ raise <<-EOF
133
+ This method must be implemented by a concrete class descending
134
+ from Generator. See generator class documentation for more
135
+ information.
136
+ EOF
137
+ end
138
+
139
+ def to_h #:nodoc:
140
+ raise <<-EOF
141
+ This method must be implemented by a concrete class descending
142
+ from Generator. See generator class documentation for more
143
+ information.
144
+ EOF
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,52 @@
1
+ require 'digest/md5'
2
+ require 'fileutils'
3
+
4
+ module MetricFu
5
+ class MD5Tracker
6
+
7
+ @@unchanged_md5s = []
8
+
9
+ class << self
10
+ def md5_dir(path_to_file, base_dir)
11
+ File.join(base_dir,
12
+ path_to_file.split('/')[0..-2].join('/'))
13
+ end
14
+
15
+ def md5_file(path_to_file, base_dir)
16
+ File.join(md5_dir(path_to_file, base_dir),
17
+ path_to_file.split('/').last.sub(/\.[a-z]+/, '.md5'))
18
+ end
19
+
20
+ def track(path_to_file, base_dir)
21
+ md5 = Digest::MD5.hexdigest(File.read(path_to_file))
22
+ FileUtils.mkdir_p(md5_dir(path_to_file, base_dir), :verbose => false)
23
+ f = File.new(md5_file(path_to_file, base_dir), "w")
24
+ f.puts(md5)
25
+ f.close
26
+ md5
27
+ end
28
+
29
+ def file_changed?(path_to_file, base_dir)
30
+ orig_md5_file = md5_file(path_to_file, base_dir)
31
+ return !!track(path_to_file, base_dir) unless File.exist?(orig_md5_file)
32
+
33
+ current_md5 = ""
34
+ file = File.open(orig_md5_file, 'r')
35
+ file.each_line { |line| current_md5 << line }
36
+ file.close
37
+ current_md5.chomp!
38
+
39
+ new_md5 = Digest::MD5.hexdigest(File.read(path_to_file))
40
+ new_md5.chomp!
41
+
42
+ @@unchanged_md5s << path_to_file if new_md5 == current_md5
43
+
44
+ return new_md5 != current_md5
45
+ end
46
+
47
+ def file_already_counted?(path_to_file)
48
+ return @@unchanged_md5s.include?(path_to_file)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,100 @@
1
+ module MetricFu
2
+
3
+ # MetricFu.report memoizes access to a Report object, that will be
4
+ # used throughout the lifecycle of the MetricFu app.
5
+ def self.report
6
+ @report ||= Report.new
7
+ end
8
+
9
+ # = Report
10
+ #
11
+ # The Report class is responsible two things:
12
+ #
13
+ # It adds information to the yaml report, produced by the system
14
+ # as a whole, for each of the generators used in this test run.
15
+ #
16
+ # It also handles passing the information from each generator used
17
+ # in this test run out to the template class set in
18
+ # MetricFu::Configuration.
19
+ class Report
20
+
21
+ # Renders the result of the report_hash into a yaml serialization
22
+ # ready for writing out to a file.
23
+ #
24
+ # @return YAML
25
+ # A YAML object containing the results of the report generation
26
+ # process
27
+ def to_yaml
28
+ report_hash.to_yaml
29
+ end
30
+
31
+
32
+ def report_hash #:nodoc:
33
+ @report_hash ||= {}
34
+ end
35
+
36
+ # Instantiates a new template class based on the configuration set
37
+ # in MetricFu::Configuration, or through the MetricFu.config block
38
+ # in your rake file (defaults to the included StandardTemplate) and
39
+ # assigns the report_hash to the report_hash to the template and
40
+ # asks itself to write itself out.
41
+ def save_templatized_report
42
+ @template = MetricFu.template_class.new
43
+ @template.report = report_hash
44
+ @template.write
45
+ end
46
+
47
+ # Adds a hash from a passed report, produced by one of the Generator
48
+ # classes to the aggregate report_hash managed by this hash.
49
+ #
50
+ # @param report_type Hash
51
+ # The hash to add to the aggregate report_hash
52
+ def add(report_type)
53
+ clazz = MetricFu.const_get(report_type.to_s.capitalize)
54
+ report_hash.merge!(clazz.generate_report)
55
+ end
56
+
57
+ # Saves the passed in content to the passed in directory. If
58
+ # a filename is passed in it will be used as the name of the
59
+ # file, otherwise it will default to 'index.html'
60
+ #
61
+ # @param content String
62
+ # A string containing the content (usually html) to be written
63
+ # to the file.
64
+ #
65
+ # @param dir String
66
+ # A dir containing the path to the directory to write the file in.
67
+ #
68
+ # @param file String
69
+ # A filename to save the path as. Defaults to 'index.html'.
70
+ #
71
+ def save_output(content, dir, file='index.html')
72
+ open("#{dir}/#{file}", "w") do |f|
73
+ f.puts content
74
+ end
75
+ end
76
+
77
+ # Checks to discover whether we should try and open the results
78
+ # of the report in the browser on this system. We only try and open
79
+ # in the browser if we're on OS X and we're not running in a
80
+ # CruiseControl.rb environment. See MetricFu.configuration for more
81
+ # details about how we make those guesses.
82
+ #
83
+ # @return Boolean
84
+ # Should we open in the browser or not?
85
+ def open_in_browser?
86
+ MetricFu.configuration.platform.include?('darwin') &&
87
+ ! MetricFu.configuration.is_cruise_control_rb?
88
+ end
89
+
90
+ # Shows 'index.html' from the passed directory in the browser
91
+ # if we're able to open the browser on this platform.
92
+ #
93
+ # @param dir String
94
+ # The directory path where the 'index.html' we want to open is
95
+ # stored
96
+ def show_in_browser(dir)
97
+ system("open #{dir}/index.html") if open_in_browser?
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,86 @@
1
+ require 'chronic'
2
+ require 'generator'
3
+ module MetricFu
4
+
5
+ class Churn < Generator
6
+
7
+ def initialize(options={})
8
+ super
9
+ if File.exist?(".git")
10
+ @source_control = Git.new(MetricFu.churn[:start_date])
11
+ elsif File.exist?(".svn")
12
+ @source_control = Svn.new(MetricFu.churn[:start_date])
13
+ else
14
+ raise "Churning requires a subversion or git repo"
15
+ end
16
+ @minimum_churn_count = MetricFu.churn[:minimum_churn_count] || 5
17
+ end
18
+
19
+ def emit
20
+ @changes = parse_log_for_changes.reject {|file, change_count| change_count < @minimum_churn_count}
21
+ end
22
+
23
+ def analyze
24
+ @changes = @changes.to_a.sort {|x,y| y[1] <=> x[1]}
25
+ @changes = @changes.map {|change| {:file_path => change[0], :times_changed => change[1] }}
26
+ end
27
+
28
+ def to_h
29
+ {:churn => {:changes => @changes}}
30
+ end
31
+
32
+ private
33
+
34
+ def parse_log_for_changes
35
+ changes = {}
36
+
37
+ logs = @source_control.get_logs
38
+ logs.each do |line|
39
+ changes[line] ? changes[line] += 1 : changes[line] = 1
40
+ end
41
+ changes
42
+ end
43
+
44
+
45
+ class SourceControl
46
+ def initialize(start_date=nil)
47
+ @start_date = start_date
48
+ end
49
+ end
50
+
51
+ class Git < SourceControl
52
+ def get_logs
53
+ `git log #{date_range} --name-only --pretty=format:`.split(/\n/).reject{|line| line == ""}
54
+ end
55
+
56
+ private
57
+ def date_range
58
+ if @start_date
59
+ date = Chronic.parse(@start_date)
60
+ "--after=#{date.strftime('%Y-%m-%d')}"
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ class Svn < SourceControl
67
+ def get_logs
68
+ `svn log #{date_range} --verbose`.split(/\n/).map { |line| clean_up_svn_line(line) }.compact
69
+ end
70
+
71
+ private
72
+ def date_range
73
+ if @start_date
74
+ date = Chronic.parse(@start_date)
75
+ "--revision {#{date.strftime('%Y-%m-%d')}}:{#{Time.now.strftime('%Y-%m-%d')}}"
76
+ end
77
+ end
78
+
79
+ def clean_up_svn_line(line)
80
+ m = line.match(/\W*[A,M]\W+(\/.*)\b/)
81
+ m ? m[1] : nil
82
+ end
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,29 @@
1
+ require 'generator'
2
+ module MetricFu
3
+
4
+ class Flay < Generator
5
+
6
+ def emit
7
+ files_to_flay = MetricFu.flay[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
8
+ @output = `flay #{files_to_flay.join(" ")}`
9
+ end
10
+
11
+ def analyze
12
+ @matches = @output.chomp.split("\n\n").map{|m| m.split("\n ") }
13
+ end
14
+
15
+ def to_h
16
+ target = []
17
+ total_score = @matches.shift.first.split('=').last.strip
18
+ @matches.each do |problem|
19
+ reason = problem.shift.strip
20
+ lines_info = problem.map do |full_line|
21
+ name, line = full_line.split(":")
22
+ {:name => name.strip, :line => line.strip}
23
+ end
24
+ target << [:reason => reason, :matches => lines_info]
25
+ end
26
+ {:flay => {:total_score => total_score, :matches => target.flatten}}
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,127 @@
1
+ module MetricFu
2
+
3
+ class Flog < Generator
4
+ attr_reader :pages
5
+
6
+ SCORE_FORMAT = "%0.2f"
7
+ METHOD_LINE_REGEX = /(\d+\.\d+):\s+([A-Za-z:]+#.*)/
8
+ OPERATOR_LINE_REGEX = /\s*(\d+\.\d+):\s(.*)$/
9
+
10
+ def emit
11
+ metric_dir = MetricFu::Flog.metric_directory
12
+ MetricFu.flog[:dirs_to_flog].each do |directory|
13
+ Dir.glob("#{directory}/**/*.rb").each do |filename|
14
+ output_dir = "#{metric_dir}/#{filename.split("/")[0..-2].join("/")}"
15
+ mkdir_p(output_dir, :verbose => false) unless File.directory?(output_dir)
16
+ if MetricFu::MD5Tracker.file_changed?(filename, metric_dir)
17
+ `flog -ad #{filename} > #{metric_dir}/#{filename.split('.')[0]}.txt`
18
+ end
19
+ end
20
+ end
21
+ rescue LoadError
22
+ if RUBY_PLATFORM =~ /java/
23
+ puts 'running in jruby - flog tasks not available'
24
+ else
25
+ puts 'sudo gem install flog # if you want the flog tasks'
26
+ end
27
+ end
28
+
29
+ def parse(text)
30
+ summary, methods_summary = text.split "\n\n"
31
+ score, average = summary.split("\n").map {|line| line[OPERATOR_LINE_REGEX, 1]}
32
+ return nil unless score && methods_summary
33
+ page = Flog::Page.new(score, average)
34
+ methods_summary.each_line do |method_line|
35
+ if match = method_line.match(METHOD_LINE_REGEX)
36
+ page.scanned_methods << ScannedMethod.new(match[2], match[1])
37
+ elsif match = method_line.match(OPERATOR_LINE_REGEX)
38
+ return if page.scanned_methods.empty?
39
+ page.scanned_methods.last.operators << Operator.new(match[1], match[2])
40
+ end
41
+ end
42
+ page
43
+ end
44
+
45
+ def analyze
46
+ @pages = []
47
+ flog_results.each do |path|
48
+ page = parse(open(path, "r") { |f| f.read })
49
+ if page
50
+ page.path = path.sub(metric_directory, "").sub(".txt", ".rb")
51
+ @pages << page
52
+ end
53
+ end
54
+ end
55
+
56
+ def to_h
57
+ number_of_methods = @pages.inject(0) {|count, page| count += page.scanned_methods.size}
58
+ total_flog_score = @pages.inject(0) {|total, page| total += page.score}
59
+ sorted_pages = @pages.sort_by {|page| page.score }.reverse
60
+ {:flog => { :total => total_flog_score,
61
+ :average => round_to_tenths(total_flog_score/number_of_methods),
62
+ :pages => sorted_pages.map {|page| page.to_h}}}
63
+ end
64
+
65
+ def flog_results
66
+ Dir.glob("#{metric_directory}/**/*.txt")
67
+ end
68
+
69
+ class Operator
70
+ attr_accessor :score, :operator
71
+
72
+ def initialize(score, operator)
73
+ @score = score.to_f
74
+ @operator = operator
75
+ end
76
+
77
+ def to_h
78
+ {:score => @score, :operator => @operator}
79
+ end
80
+ end
81
+
82
+ class ScannedMethod
83
+ attr_accessor :name, :score, :operators
84
+
85
+ def initialize(name, score, operators = [])
86
+ @name = name
87
+ @score = score.to_f
88
+ @operators = operators
89
+ end
90
+
91
+ def to_h
92
+ {:name => @name,
93
+ :score => @score,
94
+ :operators => @operators.map {|o| o.to_h}}
95
+ end
96
+ end
97
+
98
+ end
99
+
100
+ class Flog::Page < MetricFu::Generator
101
+ attr_accessor :path, :score, :scanned_methods, :average_score
102
+
103
+ def initialize(score, average_score, scanned_methods = [])
104
+ @score = score.to_f
105
+ @scanned_methods = scanned_methods
106
+ @average_score = average_score.to_f
107
+ end
108
+
109
+ def filename
110
+ File.basename(path, ".txt")
111
+ end
112
+
113
+ def to_h
114
+ {:score => @score,
115
+ :scanned_methods => @scanned_methods.map {|sm| sm.to_h},
116
+ :highest_score => highest_score,
117
+ :average_score => average_score,
118
+ :path => path}
119
+ end
120
+
121
+ def highest_score
122
+ scanned_methods.inject(0) do |highest, m|
123
+ m.score > highest ? m.score : highest
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,77 @@
1
+ require 'enumerator'
2
+
3
+ module MetricFu
4
+
5
+ class Rcov < Generator
6
+ NEW_FILE_MARKER = ("=" * 80) + "\n"
7
+
8
+
9
+ class Line
10
+ attr_accessor :content, :was_run
11
+
12
+ def initialize(content, was_run)
13
+ @content = content
14
+ @was_run = was_run
15
+ end
16
+
17
+ def to_h
18
+ {:content => @content, :was_run => @was_run}
19
+ end
20
+ end
21
+
22
+ def emit
23
+ begin
24
+ FileUtils.rm_rf(MetricFu::Rcov.metric_directory, :verbose => false)
25
+ Dir.mkdir(MetricFu::Rcov.metric_directory)
26
+ test_files = FileList[*MetricFu.rcov[:test_files]].join(' ')
27
+ rcov_opts = MetricFu.rcov[:rcov_opts].join(' ')
28
+ output = ">> #{MetricFu::Rcov.metric_directory}/rcov.txt"
29
+ `rcov --include-file #{test_files} #{rcov_opts} #{output}`
30
+ rescue LoadError
31
+ if RUBY_PLATFORM =~ /java/
32
+ puts 'running in jruby - rcov tasks not available'
33
+ else
34
+ puts 'sudo gem install rcov # if you want the rcov tasks'
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ def analyze
41
+ output = File.open(MetricFu::Rcov.metric_directory + '/rcov.txt').read
42
+ output = output.split(NEW_FILE_MARKER)
43
+ # Throw away the first entry - it's the execution time etc.
44
+ output.shift
45
+ files = {}
46
+ output.each_slice(2) {|out| files[out.first.strip] = out.last}
47
+ files.each_pair {|fname, content| files[fname] = content.split("\n") }
48
+ files.each_pair do |fname, content|
49
+ content.map! do |raw_line|
50
+ if raw_line.match(/^!!/)
51
+ line = Line.new(raw_line.gsub('!!', ' '), false).to_h
52
+ else
53
+ line = Line.new(raw_line, true).to_h
54
+ end
55
+ end
56
+ files[fname] = {:lines => content}
57
+ end
58
+
59
+ # Calculate the percentage of lines run in each file
60
+ @global_total_lines = 0
61
+ @global_total_lines_run = 0
62
+ files.each_pair do |fname, content|
63
+ lines = content[:lines]
64
+ @global_total_lines_run += lines_run = lines.find_all {|line| line[:was_run] == true }.length
65
+ @global_total_lines += total_lines = lines.length
66
+ percent_run = ((lines_run.to_f / total_lines.to_f) * 100).round
67
+ files[fname][:percent_run] = percent_run
68
+ end
69
+ @rcov = files
70
+ end
71
+
72
+ def to_h
73
+ global_percent_run = ((@global_total_lines_run.to_f / @global_total_lines.to_f) * 100)
74
+ {:rcov => @rcov.merge({:global_percent_run => round_to_tenths(global_percent_run) })}
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,32 @@
1
+ module MetricFu
2
+
3
+ class Reek < Generator
4
+ REEK_REGEX = /^(\S+) (.*) \((.*)\)$/
5
+
6
+ def emit
7
+ files_to_reek = MetricFu.reek[:dirs_to_reek].map{|dir| Dir[File.join(dir, "**/*.rb")] }
8
+ @output = `reek #{files_to_reek.join(" ")}`
9
+ end
10
+
11
+ def analyze
12
+ @matches = @output.chomp.split("\n\n").map{|m| m.split("\n") }
13
+ @matches = @matches.map do |match|
14
+ file_path = match.shift.split('--').first
15
+ file_path = file_path.gsub('"', ' ').strip
16
+ code_smells = match.map do |smell|
17
+ match_object = smell.match(REEK_REGEX)
18
+ next unless match_object
19
+ {:method => match_object[1].strip,
20
+ :message => match_object[2].strip,
21
+ :type => match_object[3].strip}
22
+ end.compact
23
+ {:file_path => file_path, :code_smells => code_smells}
24
+ end
25
+ end
26
+
27
+ def to_h
28
+ {:reek => {:matches => @matches}}
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ module MetricFu
2
+ class Roodi < Generator
3
+ def emit
4
+ files_to_analyze = MetricFu.roodi[:dirs_to_roodi].map{|dir| Dir[File.join(dir, "**/*.rb")] }
5
+ @output = `roodi #{files_to_analyze.join(" ")}`
6
+ end
7
+
8
+ def analyze
9
+ @matches = @output.chomp.split("\n").map{|m| m.split(" - ") }
10
+ total = @matches.pop
11
+ @matches.reject! {|array| array.empty? }
12
+ @matches.map! do |match|
13
+ file, line = match[0].split(':')
14
+ problem = match[1]
15
+ {:file => file, :line => line, :problem => problem}
16
+ end
17
+ @roodi_results = {:total => total, :problems => @matches}
18
+ end
19
+
20
+ def to_h
21
+ {:roodi => @roodi_results}
22
+ end
23
+ end
24
+ end