Permalink
Browse files

Change flay task to only run under MRI 1.9.3 and 2.0.0

* Each platform and version of ruby returns a different flay score,
  so we decided in devtools to standardize on 1.9.3 and 2.0.0
  scores since they seemed to be the most accurate.
  • Loading branch information...
dkubb committed Feb 27, 2013
1 parent be39b5c commit 82cacaec61dc92e57a847c53e95640247d579969
Showing with 40 additions and 32 deletions.
  1. +40 −32 tasks/metrics/flay.rake
View
@@ -1,45 +1,53 @@
# encoding: utf-8
+PLATFORM = defined?(RUBY_ENGINE) && RUBY_ENGINE || 'ruby'
+
namespace :metrics do
- begin
- require 'flay'
- require 'yaml'
-
- config = YAML.load_file(File.expand_path('../../../config/flay.yml', __FILE__)).freeze
- threshold = config.fetch('threshold').to_i
- total_score = config.fetch('total_score').to_f
- files = Flay.expand_dirs_to_files(config.fetch('path', 'lib')).sort
-
- # original code by Marty Andrews:
- # http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html
- desc 'Analyze for code duplication'
- task :flay do
- # run flay once without a threshold to ensure the max mass matches the threshold
- flay = Flay.new(:fuzzy => false, :verbose => false, :mass => 0)
- flay.process(*files)
+ if RUBY_VERSION >= '1.9.3' && PLATFORM == 'ruby'
+ begin
+ require 'flay'
+ require 'yaml'
- max = (flay.masses.map { |hash, mass| mass.to_f / flay.hashes[hash].size }.max) || 0
- unless max >= threshold
- raise "Adjust flay threshold down to #{max}"
- end
+ config = YAML.load_file(File.expand_path('../../../config/flay.yml', __FILE__)).freeze
+ threshold = config.fetch('threshold').to_i
+ total_score = config.fetch('total_score').to_f
+ files = Flay.expand_dirs_to_files(config.fetch('path', 'lib')).sort
- total = flay.masses.reduce(0.0) { |total, (hash, mass)| total + (mass.to_f / flay.hashes[hash].size) }
- unless total == total_score
- raise "Flay total is now #{total}, but expected #{total_score}"
- end
+ # original code by Marty Andrews:
+ # http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html
+ desc 'Analyze for code duplication'
+ task :flay do
+ # run flay once without a threshold to ensure the max mass matches the threshold
+ flay = Flay.new(:fuzzy => false, :verbose => false, :mass => 0)
+ flay.process(*files)
- # run flay a second time with the threshold set
- flay = Flay.new(:fuzzy => false, :verbose => false, :mass => threshold.succ)
- flay.process(*files)
+ max = (flay.masses.map { |hash, mass| mass.to_f / flay.hashes[hash].size }.max) || 0
+ unless max >= threshold
+ raise "Adjust flay threshold down to #{max}"
+ end
- if flay.masses.any?
- flay.report
- raise "#{flay.masses.size} chunks of code have a duplicate mass > #{threshold}"
+ total = flay.masses.reduce(0.0) { |total, (hash, mass)| total + (mass.to_f / flay.hashes[hash].size) }
+ unless total == total_score
+ raise "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)
+
+ if flay.masses.any?
+ flay.report
+ raise "#{flay.masses.size} chunks of code have a duplicate mass > #{threshold}"
+ end
+ end
+ rescue LoadError
+ task :flay do
+ $stderr.puts 'Flay is not available. In order to run flay, you must: gem install flay'
end
end
- rescue LoadError
+ else
task :flay do
- $stderr.puts 'Flay is not available. In order to run flay, you must: gem install flay'
+ $stderr.puts "Flay is disabled under #{PLATFORM}-#{RUBY_VERSION} since it is not score compatible with other implementations"
end
end
end

0 comments on commit 82cacae

Please sign in to comment.