flog 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +1 -1
- data/History.txt +13 -0
- data/lib/flog.rb +43 -19
- data/test/test_flog.rb +45 -2
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
|D�u�c�I(h��$�7U�|V��
|
data/History.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
=== 2.4.0 / 2009-12-15
|
2
|
+
|
3
|
+
* 4 minor enhancements:
|
4
|
+
|
5
|
+
* Cleaned method_name to return "#method" or "::method".
|
6
|
+
* DSL reporting now handles regexp literals for 'method' names (Marty Andrews)
|
7
|
+
* Improved tests for process_iter's myriad complexities.
|
8
|
+
* More doco!
|
9
|
+
|
10
|
+
* 1 bug fix:
|
11
|
+
|
12
|
+
* Fixed DSL reporting excluding solo-blocks. (eg a single rake task)
|
13
|
+
|
1
14
|
=== 2.3.0 / 2009-12-09
|
2
15
|
|
3
16
|
* 1 major enhancement:
|
data/lib/flog.rb
CHANGED
@@ -4,14 +4,14 @@ require 'ruby_parser'
|
|
4
4
|
require 'optparse'
|
5
5
|
|
6
6
|
class Flog < SexpProcessor
|
7
|
-
VERSION = '2.
|
7
|
+
VERSION = '2.4.0'
|
8
8
|
|
9
9
|
THRESHOLD = 0.60
|
10
10
|
SCORES = Hash.new 1
|
11
11
|
BRANCHING = [ :and, :case, :else, :if, :or, :rescue, :until, :when, :while ]
|
12
12
|
|
13
13
|
##
|
14
|
-
#
|
14
|
+
# Various non-call constructs
|
15
15
|
|
16
16
|
OTHER_SCORES = {
|
17
17
|
:alias => 2,
|
@@ -28,7 +28,7 @@ class Flog < SexpProcessor
|
|
28
28
|
}
|
29
29
|
|
30
30
|
##
|
31
|
-
#
|
31
|
+
# Eval forms
|
32
32
|
|
33
33
|
SCORES.merge!(:define_method => 5,
|
34
34
|
:eval => 5,
|
@@ -37,7 +37,7 @@ class Flog < SexpProcessor
|
|
37
37
|
:instance_eval => 5)
|
38
38
|
|
39
39
|
##
|
40
|
-
#
|
40
|
+
# Various "magic" usually used for "clever code"
|
41
41
|
|
42
42
|
SCORES.merge!(:alias_method => 2,
|
43
43
|
:extend => 2,
|
@@ -61,7 +61,7 @@ class Flog < SexpProcessor
|
|
61
61
|
:undef_method => 2)
|
62
62
|
|
63
63
|
##
|
64
|
-
#
|
64
|
+
# Calls that are ALMOST ALWAYS ABUSED!
|
65
65
|
|
66
66
|
SCORES.merge!(:inject => 2)
|
67
67
|
|
@@ -143,22 +143,27 @@ class Flog < SexpProcessor
|
|
143
143
|
option
|
144
144
|
end
|
145
145
|
|
146
|
+
##
|
147
|
+
# Add a score to the tally. Score can be predetermined or looked up
|
148
|
+
# automatically. Uses multiplier for additional spankings.
|
149
|
+
# Spankings!
|
150
|
+
|
146
151
|
def add_to_score name, score = OTHER_SCORES[name]
|
147
152
|
@calls[signature][name] += score * @multiplier
|
148
153
|
end
|
149
154
|
|
150
155
|
##
|
151
|
-
#
|
152
|
-
|
153
|
-
def process_until_empty exp
|
154
|
-
process exp.shift until exp.empty?
|
155
|
-
end
|
156
|
+
# really?
|
156
157
|
|
157
158
|
def average
|
158
159
|
return 0 if calls.size == 0
|
159
160
|
total / calls.size
|
160
161
|
end
|
161
162
|
|
163
|
+
##
|
164
|
+
# Flog the given files or directories. Smart. Deals with "-", syntax
|
165
|
+
# errors, and traversing subdirectories intelligently.
|
166
|
+
|
162
167
|
def flog(*files_or_dirs)
|
163
168
|
files = Flog.expand_dirs_to_files(*files_or_dirs)
|
164
169
|
|
@@ -198,8 +203,8 @@ class Flog < SexpProcessor
|
|
198
203
|
# Adds name to the method stack, for the duration of the block
|
199
204
|
|
200
205
|
def in_method(name, file, line)
|
201
|
-
|
202
|
-
|
206
|
+
method_name = Regexp === name ? name.inspect : name.to_s
|
207
|
+
@method_stack.unshift method_name
|
203
208
|
@method_locations[signature] = "#{file}:#{line}"
|
204
209
|
yield
|
205
210
|
@method_stack.shift
|
@@ -240,15 +245,18 @@ class Flog < SexpProcessor
|
|
240
245
|
end
|
241
246
|
|
242
247
|
##
|
243
|
-
# Returns the first method in the list, or
|
248
|
+
# Returns the first method in the list, or "#none" if there are
|
244
249
|
# none.
|
245
250
|
|
246
251
|
def method_name
|
247
252
|
m = @method_stack.first || @@no_method
|
248
|
-
m = "##{m}" unless m =~ /::/
|
253
|
+
m = "##{m}" unless m =~ /::/
|
249
254
|
m
|
250
255
|
end
|
251
256
|
|
257
|
+
##
|
258
|
+
# Output the report up to a given max or report everything, if nil.
|
259
|
+
|
252
260
|
def output_details(io, max = nil)
|
253
261
|
my_totals = totals
|
254
262
|
current = 0
|
@@ -287,13 +295,16 @@ class Flog < SexpProcessor
|
|
287
295
|
end
|
288
296
|
end
|
289
297
|
|
298
|
+
##
|
299
|
+
# Output the details for a method
|
300
|
+
|
290
301
|
def output_method_details(io, class_method, call_list)
|
291
302
|
return 0 if option[:methods] and class_method =~ /##{@@no_method}/
|
292
303
|
|
293
304
|
total = totals[class_method]
|
294
305
|
|
295
306
|
location = @method_locations[class_method]
|
296
|
-
if location then
|
307
|
+
if location then # REFACTOR
|
297
308
|
io.puts "%8.1f: %-32s %s" % [total, class_method, location]
|
298
309
|
else
|
299
310
|
io.puts "%8.1f: %s" % [total, class_method]
|
@@ -321,6 +332,13 @@ class Flog < SexpProcessor
|
|
321
332
|
@multiplier -= bonus
|
322
333
|
end
|
323
334
|
|
335
|
+
##
|
336
|
+
# Process each element of #exp in turn.
|
337
|
+
|
338
|
+
def process_until_empty exp
|
339
|
+
process exp.shift until exp.empty?
|
340
|
+
end
|
341
|
+
|
324
342
|
##
|
325
343
|
# Report results to #io, STDOUT by default.
|
326
344
|
|
@@ -339,12 +357,18 @@ class Flog < SexpProcessor
|
|
339
357
|
self.reset
|
340
358
|
end
|
341
359
|
|
360
|
+
##
|
361
|
+
# Reset score data
|
362
|
+
|
342
363
|
def reset
|
343
364
|
@totals = @total_score = nil
|
344
365
|
@multiplier = 1.0
|
345
366
|
@calls = Hash.new { |h,k| h[k] = Hash.new 0 }
|
346
367
|
end
|
347
368
|
|
369
|
+
##
|
370
|
+
# Compute the distance formula for a given tally
|
371
|
+
|
348
372
|
def score_method(tally)
|
349
373
|
a, b, c = 0, 0, 0
|
350
374
|
tally.each do |cat, score|
|
@@ -358,9 +382,7 @@ class Flog < SexpProcessor
|
|
358
382
|
end
|
359
383
|
|
360
384
|
def signature
|
361
|
-
|
362
|
-
m = "#none" if m == @@no_method
|
363
|
-
"#{klass_name}#{m}" # FIX: ugly
|
385
|
+
"#{klass_name}#{method_name}"
|
364
386
|
end
|
365
387
|
|
366
388
|
def total # FIX: I hate this indirectness
|
@@ -525,7 +547,9 @@ class Flog < SexpProcessor
|
|
525
547
|
|
526
548
|
def process_iter(exp)
|
527
549
|
context = (self.context - [:class, :module, :scope])
|
528
|
-
|
550
|
+
context = context.uniq.sort_by { |s| s.to_s }
|
551
|
+
|
552
|
+
if context == [:block, :iter] or context == [:iter] then
|
529
553
|
recv = exp.first
|
530
554
|
|
531
555
|
# DSL w/ names. eg task :name do ... end
|
data/test/test_flog.rb
CHANGED
@@ -167,14 +167,14 @@ class TestFlog < MiniTest::Unit::TestCase
|
|
167
167
|
end
|
168
168
|
|
169
169
|
def test_method_name
|
170
|
-
assert_equal
|
170
|
+
assert_equal "#none", @flog.method_name
|
171
171
|
|
172
172
|
@flog.method_stack << "whatevs"
|
173
173
|
assert_equal "#whatevs", @flog.method_name
|
174
174
|
end
|
175
175
|
|
176
176
|
def test_method_name_cls
|
177
|
-
assert_equal
|
177
|
+
assert_equal "#none", @flog.method_name
|
178
178
|
|
179
179
|
@flog.method_stack << "::whatevs"
|
180
180
|
assert_equal "::whatevs", @flog.method_name
|
@@ -403,6 +403,36 @@ class TestFlog < MiniTest::Unit::TestCase
|
|
403
403
|
util_process sexp, 2.326, :loop => 1.0, :branch => 2.1
|
404
404
|
end
|
405
405
|
|
406
|
+
def test_process_iter_dsl
|
407
|
+
# task :blah do
|
408
|
+
# something
|
409
|
+
# end
|
410
|
+
|
411
|
+
sexp = s(:iter,
|
412
|
+
s(:call, nil, :task, s(:arglist, s(:lit, :blah))),
|
413
|
+
nil,
|
414
|
+
s(:call, nil, :something, s(:arglist)))
|
415
|
+
|
416
|
+
@klass, @meth = "task", "#blah"
|
417
|
+
|
418
|
+
util_process sexp, 2.0, :something => 1.0, :task => 1.0
|
419
|
+
end
|
420
|
+
|
421
|
+
def test_process_iter_dsl_regexp
|
422
|
+
# task /regexp/ do
|
423
|
+
# something
|
424
|
+
# end
|
425
|
+
|
426
|
+
sexp = s(:iter,
|
427
|
+
s(:call, nil, :task, s(:arglist, s(:lit, /regexp/))),
|
428
|
+
nil,
|
429
|
+
s(:call, nil, :something, s(:arglist)))
|
430
|
+
|
431
|
+
@klass, @meth = "task", "#/regexp/"
|
432
|
+
|
433
|
+
util_process sexp, 2.0, :something => 1.0, :task => 1.0
|
434
|
+
end
|
435
|
+
|
406
436
|
def test_process_lit
|
407
437
|
sexp = s(:lit, :y)
|
408
438
|
util_process sexp, 0.0
|
@@ -513,6 +543,19 @@ class TestFlog < MiniTest::Unit::TestCase
|
|
513
543
|
:branch => 4.0)
|
514
544
|
end
|
515
545
|
|
546
|
+
def test_signature
|
547
|
+
assert_equal "main#none", @flog.signature
|
548
|
+
|
549
|
+
@flog.class_stack << "X"
|
550
|
+
assert_equal "X#none", @flog.signature
|
551
|
+
|
552
|
+
@flog.method_stack << "y"
|
553
|
+
assert_equal "X#y", @flog.signature
|
554
|
+
|
555
|
+
@flog.class_stack.shift
|
556
|
+
assert_equal "main#y", @flog.signature
|
557
|
+
end
|
558
|
+
|
516
559
|
def test_total
|
517
560
|
@flog.add_to_score "blah", 2
|
518
561
|
assert_equal 2.0, @flog.total
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Davis
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
FBHgymkyj/AOSqKRIpXPhjC6
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2009-12-
|
33
|
+
date: 2009-12-15 00:00:00 -08:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
metadata.gz.sig
CHANGED
Binary file
|