class Fudge::Tasks::Flog

Allow use of Flog complexity analyser

task :flog

runs flog with max score of 10.0 for a method, 5.0 average

task :flog, :exclude => 'subpath/'

excludes files matching :exclude from run

task :flog, :max => 20.0

sets max score for a method to 20.0

task :flog, :average => 10.0

sets required average to 10.0

task :flog, :methods => true

runs only scoring methods, not classes macros etc

Any and all options can be defined

Private Instance Methods

average_required() click to toggle source
# File lib/fudge/tasks/flog.rb, line 60
def average_required
  options.fetch(:average, 5.0).to_f
end
check_for() click to toggle source
# File lib/fudge/tasks/flog.rb, line 41
def check_for
  [check_regex, method(:flog_checker)]
end
check_regex() click to toggle source
# File lib/fudge/tasks/flog.rb, line 45
def check_regex
  /^\s*(?<score>\d+.\d+): (?<type>.*)$/
end
cmd(options={}) click to toggle source
# File lib/fudge/tasks/flog.rb, line 32
def cmd(options={})
  bundle_cmd(flog_ruby_files, options)
end
extract_lines(matches) click to toggle source
# File lib/fudge/tasks/flog.rb, line 78
def extract_lines(matches)
  output = matches.string
  output.scan(check_regex)
end
extract_scores(matches) click to toggle source
# File lib/fudge/tasks/flog.rb, line 68
def extract_scores(matches)
  values = top_3_lines(matches)
  total, average, max = values.map(&:to_f)
  [average, (max || 0.0), total]
end
flog_checker(matches) click to toggle source
# File lib/fudge/tasks/flog.rb, line 49
def flog_checker(matches)
  average, max = extract_scores(matches)
  if average > average_required
    "Average Complexity Higher Than #{average_required}"
  elsif max > max_score
    "Maximum Complexity Higher Than #{max_score}"
  else
    true
  end
end
flog_ruby_files() click to toggle source
# File lib/fudge/tasks/flog.rb, line 36
def flog_ruby_files
  finder = FileFinder.new(options)
  finder.generate_command("flog", tty_options)
end
max_score() click to toggle source
# File lib/fudge/tasks/flog.rb, line 64
def max_score
  options.fetch(:max, 10.0).to_f
end
top_3_lines(matches) click to toggle source
# File lib/fudge/tasks/flog.rb, line 74
def top_3_lines(matches)
  extract_lines(matches).take(3).map(&:first)
end
tty_options() click to toggle source
# File lib/fudge/tasks/flog.rb, line 83
def tty_options
  opts = []
  opts << "-m" if options[:methods]
  opts
end