updated to work with miniunit 1.1.0
[augment.git] / lib / backends / flog_backend.rb
blob17dd69763a2a4e962cc86f9ea6271ed3acdf35bd
1 require 'flog'
3 ##
4 # Gather complexity metrics about a piece of code via flog
6 class FlogBackend < Backend
7   class << self
8     def run(file)
9       @file = file
10       @layers = {}
12       flogger = Flog.new
13       flogger.flog_files @file
14       flogger.totals.each { |method, score| record method, score }
15       write_layers
16     end
18     def record(method, score)
19       return if method =~ /\#none$/ # tossing this stuff
20       color = 'red' # TODO: determine color smartly
21       message = "#{method} flogs at #{score}"
22       (@layers[@file] ||= []) << Layer.new(method, color, message, self, @file)
23     end
24   end
26   Augment::BACKENDS['flog'] = self
27 end