class FlayTask

Attributes

dirs[RW]

What directories to operate on. Sensible defaults.

name[RW]

The name of the task. Defaults to :flay

threshold[RW]

Threshold to fail the task at. Default 200.

verbose[RW]

Verbosity of output. Defaults to rake's trace (-t) option.

Public Class Methods

new(name = :flay, threshold = 200, dirs = nil) { |self| ... } click to toggle source

Creates a new FlayTask instance with given name, threshold, and dirs.

# File lib/flay_task.rb, line 28
def initialize name = :flay, threshold = 200, dirs = nil
  @name      = name
  @dirs      = dirs || %w(app bin lib spec test)
  @threshold = threshold
  @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

Defines the flay task.

# File lib/flay_task.rb, line 44
def define
  desc "Analyze for code duplication in: #{dirs.join(", ")}"
  task name do
    require "flay"
    flay = Flay.run
    flay.report if verbose

    raise "Flay total too high! #{flay.total} > #{threshold}" if
      flay.total > threshold
  end
  self
end