Class: FlogTask

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :flog, threshold = 200, dirs = nil, method = nil) {|_self| ... } ⇒ FlogTask

Returns a new instance of FlogTask.

Yields:

  • (_self)

Yield Parameters:

  • _self (FlogTask)

    the object that the method was called on



10
11
12
13
14
15
16
17
18
19
20
21
22
# 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

Instance Attribute Details

#dirsObject

Returns the value of attribute dirs.



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

def dirs
  @dirs
end

#methodObject

Returns the value of attribute method.



8
9
10
# File 'lib/flog_task.rb', line 8

def method
  @method
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#thresholdObject

Returns the value of attribute threshold.



6
7
8
# File 'lib/flog_task.rb', line 6

def threshold
  @threshold
end

#verboseObject

Returns the value of attribute verbose.



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

def verbose
  @verbose
end

Instance Method Details

#defineObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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