Class: FlogTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- FlogTask
- Defined in:
- lib/flog_task.rb
Overview
A rake front-end for flog, allowing task creation with options for verbosity, reporting, and a failure threshold.
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
.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/flog_task.rb', line 37 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.
16 17 18 |
# File 'lib/flog_task.rb', line 16 def dirs @dirs end |
#method ⇒ Object
Method to use to score. Defaults to :total_score
31 32 33 |
# File 'lib/flog_task.rb', line 31 def method @method end |
#name ⇒ Object
The name of the task. Defaults to :flog
11 12 13 |
# File 'lib/flog_task.rb', line 11 def name @name end |
#threshold ⇒ Object
Threshold to fail the task at. Default 200.
21 22 23 |
# File 'lib/flog_task.rb', line 21 def threshold @threshold end |
#verbose ⇒ Object
Verbosity of output. Defaults to rake’s trace (-t) option.
26 27 28 |
# File 'lib/flog_task.rb', line 26 def verbose @verbose end |
Instance Method Details
#define ⇒ Object
Defines the flog task.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/flog_task.rb', line 55 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 |