Class: FlayTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/flay_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :flay, threshold = 200, dirs = nil) {|_self| ... } ⇒ FlayTask

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

Yields:

  • (_self)

Yield Parameters:

  • _self (FlayTask)

    the object that the method was called on



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/flay_task.rb', line 26

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

Instance Attribute Details

#dirsObject

What directories to operate on. Sensible defaults.



10
11
12
# File 'lib/flay_task.rb', line 10

def dirs
  @dirs
end

#nameObject

The name of the task. Defaults to :flay



5
6
7
# File 'lib/flay_task.rb', line 5

def name
  @name
end

#thresholdObject

Threshold to fail the task at. Default 200.



15
16
17
# File 'lib/flay_task.rb', line 15

def threshold
  @threshold
end

#verboseObject

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



20
21
22
# File 'lib/flay_task.rb', line 20

def verbose
  @verbose
end

Instance Method Details

#defineObject

Defines the flay task.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/flay_task.rb', line 42

def define
  desc "Analyze for code duplication in: #{dirs.join(', ')}"
  task name do
    require "flay"
    flay = Flay.new
    flay.process(*Flay.expand_dirs_to_files(dirs))
    flay.report if verbose

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