class FlogTask

Attributes

dirs[RW]
method[RW]
name[RW]
threshold[RW]
verbose[RW]

Public Class Methods

new(name = :flog, threshold = 200, dirs = nil, method = nil) { |self| ... } click to toggle source
# File lib/flog_task.rb, line 10
def initialize name = :flog, threshold = 200, dirs = nil, method = nil
  @name      = name
  @dirs      = dirs || %w(app bin lib spec test)
  @threshold = threshold
  @method    = method || :total
  @verbose   = Rake.application.options.trace

  yield self if block_given?

  @dirs.reject! { |f| ! File.directory? f }

  define
end

Public Instance Methods

define() click to toggle source
# File lib/flog_task.rb, line 24
def define
  desc "Analyze for code complexity in: #{dirs.join(', ')}"
  task name do
    require "flog"
    flog = Flog.new :continue => true, :quiet => true
    flog.flog(*dirs)

    desc, score = flog.send method
    desc, score = "total", desc unless score # total only returns a number

    flog.report if verbose

    raise "Flog score for #{desc} is too high! #{score} > #{threshold}" if
      score > threshold
  end

  self
end