Sha256: cd7e7465caa070b4a10648cce5fb705d76139b814c00be26b3d1acbdf05b678b
Contents?: true
Size: 1.33 KB
Versions: 3
Compression:
Stored size: 1.33 KB
Contents
# encoding: utf-8 namespace :metrics do require 'flay' project = Devtools.project config = project.flay # Original code by Marty Andrews: # http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html desc 'Measure code duplication' task :flay do threshold = config.threshold total_score = config.total_score files = Flay.expand_dirs_to_files(config.lib_dirs).sort # Run flay first to ensure the max mass matches the threshold flay = Flay.new(fuzzy: false, verbose: false, mass: 0) flay.process(*files) flay.analyze masses = flay.masses.map do |hash, mass| Rational(mass, flay.hashes[hash].size) end max = (masses.max || 0).to_i unless max >= threshold Devtools.notify_metric_violation "Adjust flay threshold down to #{max}" end total = masses.inject(:+).to_i unless total == total_score Devtools.notify_metric_violation "Flay total is now #{total}, but expected #{total_score}" end # Run flay a second time with the threshold set flay = Flay.new(fuzzy: false, verbose: false, mass: threshold.succ) flay.process(*files) flay.analyze mass_size = flay.masses.size if mass_size.nonzero? flay.report Devtools.notify_metric_violation "#{mass_size} chunks have a duplicate mass > #{threshold}" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
devtools-0.1.2 | tasks/metrics/flay.rake |
devtools-0.1.1 | tasks/metrics/flay.rake |
devtools-0.1.0 | tasks/metrics/flay.rake |