Class: FlogTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- FlogTask
- Defined in:
- lib/flog_task.rb
Instance Attribute Summary collapse
-
#dirs ⇒ Object
What directories to operate on.
-
#method ⇒ Object
Method to use to score.
-
#name ⇒ Object
The name of the task.
-
#threshold ⇒ Object
Threshold to fail the task at.
-
#verbose ⇒ Object
Verbosity of output.
Instance Method Summary collapse
-
#define ⇒ Object
Defines the flog task.
-
#initialize(name = :flog, threshold = 200, dirs = nil, method = nil, methods_only = false) {|_self| ... } ⇒ FlogTask
constructor
Creates a new FlogTask instance with given
name
,threshold
,dirs
, andmethod
.
Constructor Details
#initialize(name = :flog, threshold = 200, dirs = nil, method = nil, methods_only = false) {|_self| ... } ⇒ FlogTask
Creates a new FlogTask instance with given name
, threshold
, dirs
, and method
.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/flog_task.rb', line 33 def initialize name = :flog, threshold = 200, dirs = nil, method = nil, methods_only = false @name = name @dirs = dirs || %w(app bin lib spec test) @threshold = threshold @method = method || :total_score @verbose = Rake.application..trace @methods_only = methods_only yield self if block_given? @dirs.reject! { |f| ! File.directory? f } define end |
Instance Attribute Details
#dirs ⇒ Object
What directories to operate on. Sensible defaults.
12 13 14 |
# File 'lib/flog_task.rb', line 12 def dirs @dirs end |
#method ⇒ Object
Method to use to score. Defaults to :total_score
27 28 29 |
# File 'lib/flog_task.rb', line 27 def method @method end |
#name ⇒ Object
The name of the task. Defaults to :flog
7 8 9 |
# File 'lib/flog_task.rb', line 7 def name @name end |
#threshold ⇒ Object
Threshold to fail the task at. Default 200.
17 18 19 |
# File 'lib/flog_task.rb', line 17 def threshold @threshold end |
#verbose ⇒ Object
Verbosity of output. Defaults to rake’s trace (-t) option.
22 23 24 |
# File 'lib/flog_task.rb', line 22 def verbose @verbose end |
Instance Method Details
#define ⇒ Object
Defines the flog task.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/flog_task.rb', line 51 def define desc "Analyze for code complexity in: #{dirs.join(', ')}" task name do require "flog_cli" flog = FlogCLI.new :continue => true, :quiet => true, :methods => @methods_only = PathExpander.new dirs, "**/*.{rb,rake}" files = .process flog.flog(*files) 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 |