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

Returns a new instance of FlayTask.

Yields:

  • (_self)

Yield Parameters:

  • _self (FlayTask)

    the object that the method was called on



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/flay_task.rb', line 7

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

Returns the value of attribute dirs.



3
4
5
# File 'lib/flay_task.rb', line 3

def dirs
  @dirs
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/flay_task.rb', line 2

def name
  @name
end

#thresholdObject

Returns the value of attribute threshold.



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

def threshold
  @threshold
end

#verboseObject

Returns the value of attribute verbose.



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

def verbose
  @verbose
end

Instance Method Details

#defineObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flay_task.rb', line 20

def define
  desc "Analyze for code duplication in: #{dirs.join(', ')}"
  task name do
    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