Sha256: 4a2b5d0b49e12d8a0f77611302846811d4d34d9a1fadab6b4193284382020b61
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
# encoding: utf-8 namespace :metrics do require 'flog' require 'flog_cli' project = Devtools.project config = project.flog # Original code by Marty Andrews: # http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html desc 'Measure code complexity' task :flog do threshold = config.threshold.to_f.round(1) flog = Flog.new flog.flog(*FlogCLI.expand_dirs_to_files(config.lib_dirs)) totals = flog.totals.select { |name, score| name[-5, 5] != '#none' } .map { |name, score| [name, score.round(1)] } .sort_by { |name, score| score } if totals.any? max = totals.last[1] unless max >= threshold Devtools.notify_metric_violation "Adjust flog score down to #{max}" end end bad_methods = totals.select { |name, score| score > threshold } if bad_methods.any? bad_methods.reverse_each do |name, score| printf "%8.1f: %s\n", score, name end Devtools.notify_metric_violation( "#{bad_methods.size} methods have a flog complexity > #{threshold}" ) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
devtools-0.1.2 | tasks/metrics/flog.rake |
devtools-0.1.1 | tasks/metrics/flog.rake |
devtools-0.1.0 | tasks/metrics/flog.rake |