Fixes for #11 and #12 #13

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@aselder
aselder commented Nov 7, 2012

Add the max_score and max_method to Flog.
max_score returns the score of the highest scoring method
max_method returns and an array of [method_name, score] for the highest
scoring method.

Adjusted FlogTask to be able to fail either on total flog score or high
scoring method threshholds.

Made FlogTask actually work (option[:parser] was never getting set)

Andrew Selder Add max_score methods, make FlogTask work.
Add the max_score and max_method to Flog.
max_score returns the score of the highest scoring method
max_method returns and an array of [method_name, score] for the highest
scoring method.

Adjusted FlogTask to be able to fail either on total flog score or high
scoring method threshholds.

Made FlogTask actually work (option[:parser] was never getting set)
a9a63df
@zenspider zenspider commented on the diff Nov 9, 2012
test/test_flog.rb
@@ -672,6 +672,24 @@ def test_total
assert_equal 2.0, @flog.total
end
+ def test_max_method
+ @flog.instance_variable_set :@calls, {
@zenspider
zenspider Nov 9, 2012 Seattle Ruby Brigade member

Rather than a clunky instance_variable_set, I simply added an attr_writer to the test file.

@zenspider zenspider commented on the diff Nov 9, 2012
lib/flog.rb
@@ -487,6 +487,14 @@ def total # FIX: I hate this indirectness
@total_score
end
+ def max_score
+ max_method[1]
+ end
+
+ def max_method
+ totals.max { |a, b| a[1] <=> b[1] }
+ end
+
@zenspider
zenspider Nov 9, 2012 Seattle Ruby Brigade member

kept as-is

@zenspider zenspider commented on the diff Nov 9, 2012
lib/flog_task.rb
@@ -22,12 +26,31 @@ def define
task name do
require "flog"
flog = Flog.new
+ flog.options[:parser] = case parser
@zenspider
zenspider Nov 9, 2012 Seattle Ruby Brigade member

I tossed all of this in favor of pushing the problem down to Flog itself. It should have been smarter.

@zenspider zenspider commented on the diff Nov 9, 2012
lib/flog_task.rb
flog.report if verbose
- raise "Flog total too high! #{flog.total} > #{threshold}" if
- flog.total > threshold
+ case fail_method
+ when :total
@zenspider
zenspider Nov 9, 2012 Seattle Ruby Brigade member

I tossed all of this in favor of a simple send. total might not respond with a textual description, but it is easy enough to backfill that for compatibility's sake.

@zenspider
Member

Done. thanks!

@zenspider zenspider closed this Nov 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment