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



28
29
30
31
32
33
34
35
36
37
38
39
# 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

Instance Attribute Details

#dirsObject

What directories to operate on. Sensible defaults.



12
13
14
# File 'lib/flay_task.rb', line 12

def dirs
  @dirs
end

#nameObject

The name of the task. Defaults to :flay



7
8
9
# File 'lib/flay_task.rb', line 7

def name
  @name
end

#thresholdObject

Threshold to fail the task at. Default 200.



17
18
19
# File 'lib/flay_task.rb', line 17

def threshold
  @threshold
end

#verboseObject

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



22
23
24
# File 'lib/flay_task.rb', line 22

def verbose
  @verbose
end

Instance Method Details

#defineObject

Defines the flay task.



44
45
46
47
48
49
50
51
52
53
54
55
# 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(dirs)
    flay.report if verbose

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