Skip to content
Browse files

100% doco

[git-p4: depot-paths = "//src/flog/dev/": change = 8359]
  • Loading branch information...
1 parent c0b8d19 commit 360ca6d9e0137adb1969b0aad3b617c023d1ff4d @zenspider zenspider committed Mar 30, 2013
Showing with 74 additions and 3 deletions.
  1. +46 −3 lib/flog.rb
  2. +26 −0 lib/flog_task.rb
  3. +2 −0 lib/gauntlet_flog.rb
View
49 lib/flog.rb
@@ -5,18 +5,29 @@
require 'timeout'
class File
- RUBY19 = "<3".respond_to? :encoding unless defined? RUBY19
+ RUBY19 = "<3".respond_to? :encoding unless defined? RUBY19 # :nodoc:
class << self
alias :binread :read unless RUBY19
end
end
class Flog < SexpProcessor
- VERSION = "3.2.3"
+ VERSION = "3.2.3" # :nodoc:
+
+ ##
+ # Cut off point where the report should stop unless --all given.
THRESHOLD = 0.60
+
+ ##
+ # The scoring system hash. Maps node type to score.
+
SCORES = Hash.new 1
+
+ ##
+ # Names of nodes that branch.
+
BRANCHING = [ :and, :case, :else, :if, :or, :rescue, :until, :when, :while ]
##
@@ -78,16 +89,24 @@ class Flog < SexpProcessor
@@no_class = :main
@@no_method = :none
+ # :stopdoc:
attr_accessor :multiplier
attr_reader :calls, :option, :class_stack, :method_stack, :mass, :sclass
attr_reader :method_locations
+ # :startdoc:
+
+ ##
+ # The known plugins for Flog. See Flog.load_plugins.
def self.plugins
@plugins ||= {}
end
- # TODO: I think I want to do this more like hoe's plugin system. Generalize?
+ ##
+ # Loads all flog plugins. Files must be named "flog/*.rb".
+
def self.load_plugins
+ # TODO: I think I want to do this more like hoe's plugin system. Generalize?
loaded, found = {}, {}
Gem.find_files("flog/*.rb").reverse.each do |path|
@@ -117,7 +136,11 @@ def self.load_plugins
end
end
+ ##
+ # Expands +*dirs+ to all files within that match ruby and rake extensions.
+ # --
# REFACTOR: from flay
+
def self.expand_dirs_to_files *dirs
extensions = %w[rb rake]
@@ -130,6 +153,9 @@ def self.expand_dirs_to_files *dirs
}.flatten.sort
end
+ ##
+ # Parse options in +args+ (defaults to ARGV).
+
def self.parse_options args = ARGV
option = {
:quiet => false,
@@ -337,6 +363,9 @@ def in_method(name, file, line)
@method_stack.shift
end
+ ##
+ # Creates a new Flog instance with +options+.
+
def initialize option = {}
super()
@option = option
@@ -497,20 +526,32 @@ def score_method(tally)
Math.sqrt(a*a + b*b + c*c)
end
+ ##
+ # Returns the method signature for the current method.
+
def signature
"#{klass_name}#{method_name}"
end
+ ##
+ # Calculates and returns the score (and total score on the side).
+
def total # FIX: I hate this indirectness
totals unless @total_score # calculates total_score as well
@total_score
end
+ ##
+ # Returns the maximum score for a single method. Used for FlogTask.
+
def max_score
max_method.last
end
+ ##
+ # Returns the method/score pair of the maximum score.
+
def max_method
totals.max_by { |_, score| score }
end
@@ -538,6 +579,7 @@ def totals
############################################################
# Process Methods:
+ # :stopdoc:
def process_alias(exp)
process exp.shift
process exp.shift
@@ -791,4 +833,5 @@ def process_yield(exp)
process_until_empty exp
s()
end
+ # :startdoc:
end
View
26 lib/flog_task.rb
@@ -1,12 +1,35 @@
require 'rake/tasklib'
class FlogTask < Rake::TaskLib
+ ##
+ # The name of the task. Defaults to :flog
+
attr_accessor :name
+
+ ##
+ # What directories to operate on. Sensible defaults.
+
attr_accessor :dirs
+
+ ##
+ # Threshold to fail the task at. Default 200.
+
attr_accessor :threshold
+
+ ##
+ # Verbosity of output. Defaults to rake's trace (-t) option.
+
attr_accessor :verbose
+
+ ##
+ # Method to use to score. Defaults to :total
+
attr_accessor :method
+ ##
+ # Creates a new FlogTask instance with given +name+, +threshold+,
+ # +dirs+, and +method+.
+
def initialize name = :flog, threshold = 200, dirs = nil, method = nil
@name = name
@dirs = dirs || %w(app bin lib spec test)
@@ -21,6 +44,9 @@ def initialize name = :flog, threshold = 200, dirs = nil, method = nil
define
end
+ ##
+ # Defines the flog task.
+
def define
desc "Analyze for code complexity in: #{dirs.join(', ')}"
task name do
View
2 lib/gauntlet_flog.rb
@@ -10,6 +10,7 @@
require 'gauntlet'
require 'pp'
+# :stopdoc:
class FlogGauntlet < Gauntlet
$owners = {}
$score_file = 'flog-scores.yml'
@@ -191,3 +192,4 @@ def group_by_owner
flogger = FlogGauntlet.new
flogger.run_the_gauntlet filter
flogger.display_report max
+# :startdoc:

0 comments on commit 360ca6d

Please sign in to comment.
Something went wrong with that request. Please try again.