Ruby Metric Adapter
There are a bevy of useful static analysis tools for ruby, but each tool provides a slightly different set of metrics that have different APIs. Flog measures complexity, Flay measures code duplication, while Reek uses heuristics to find code smells. What if you want to use them all together? MetricAdapter provides a uniform interface for consuming the metrics these tools provide.
For instance, here is a script that lists issues found by Flog and Reek:
require 'flog'
require 'reek'
require 'metric_adapter'
paths = ARGV
metrics = []
# Generate flog metrics.
flog = Flog.new :quiet => true, :continue => true
flog.flog(*paths)
metrics += MetricAdapter::FlogAdapter.new(flog).metrics
# Generate Reek metrics.
reek = Reek::Examiner.new(paths)
metrics += MetricAdapter::ReekAdapter.new(reek).metrics
# Report on the adapted metrics
metrics.sort_by{|m| m.location }.each do |m|
puts "#{m.location} - #{m.message}"
end
Currently there is support for Flog, Flay, and Reek. If you would like to add a new adapter, send me a pull request.