flog 3.0.0.b2 → 3.0.0.b3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +9 -0
  3. data/lib/flog.rb +22 -8
  4. data/test/test_flog.rb +51 -0
  5. metadata +12 -12
  6. metadata.gz.sig +0 -0
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ === 3.0.0.b3 / 2012-10-22
2
+
3
+ * 4 minor enhancements:
4
+
5
+ * Added .rake as a supported extension.
6
+ * Create a new parser for every file, preventing state barkification
7
+ * Extended DSL support to include hash args (eg task :blah => :dep).
8
+ * Extended DSL support to report nested names (eg namespace(blah)::task#woot)
9
+
1
10
  === 3.0.0.b2 / 2012-08-07
2
11
 
3
12
  * 1 bug fix:
data/lib/flog.rb CHANGED
@@ -12,7 +12,7 @@ class File
12
12
  end
13
13
 
14
14
  class Flog < SexpProcessor
15
- VERSION = '3.0.0.b2'
15
+ VERSION = '3.0.0.b3'
16
16
 
17
17
  THRESHOLD = 0.60
18
18
  SCORES = Hash.new 1
@@ -118,7 +118,7 @@ class Flog < SexpProcessor
118
118
 
119
119
  # REFACTOR: from flay
120
120
  def self.expand_dirs_to_files *dirs
121
- extensions = ['rb']
121
+ extensions = %w[rb rake]
122
122
 
123
123
  dirs.flatten.map { |p|
124
124
  if File.directory? p then
@@ -255,6 +255,7 @@ class Flog < SexpProcessor
255
255
  ruby = file == '-' ? $stdin.read : File.binread(file)
256
256
  warn "** flogging #{file}" if option[:verbose]
257
257
 
258
+ @parser = option[:parser].new
258
259
  ast = @parser.process(ruby, file)
259
260
  next unless ast
260
261
  mass[file] = ast.mass
@@ -317,7 +318,7 @@ class Flog < SexpProcessor
317
318
  @method_stack = []
318
319
  @method_locations = {}
319
320
  @mass = {}
320
- @parser = option[:parser].new
321
+ @parser = nil
321
322
  self.auto_shift_type = true
322
323
  self.reset
323
324
  end
@@ -332,7 +333,7 @@ class Flog < SexpProcessor
332
333
  if Sexp === name then
333
334
  raise "you shouldn't see me"
334
335
  elsif @class_stack.any?
335
- @class_stack.reverse.join("::")
336
+ @class_stack.reverse.join("::").sub(/\([^\)]+\)$/, '')
336
337
  else
337
338
  @@no_class
338
339
  end
@@ -637,6 +638,15 @@ class Flog < SexpProcessor
637
638
  s()
638
639
  end
639
640
 
641
+ def dsl_name? args
642
+ return false unless args and not args.empty?
643
+
644
+ first_arg = args.first
645
+ first_arg = first_arg[1] if first_arg[0] == :hash
646
+
647
+ [:lit, :str].include? first_arg[0] and first_arg[1]
648
+ end
649
+
640
650
  def process_iter(exp)
641
651
  context = (self.context - [:class, :module, :scope])
642
652
  context = context.uniq.sort_by { |s| s.to_s }
@@ -646,10 +656,14 @@ class Flog < SexpProcessor
646
656
 
647
657
  # DSL w/ names. eg task :name do ... end
648
658
  # looks like s(:call, nil, :task, s(:lit, :name))
649
- t, r, m, a = recv
650
- if (t == :call and r == nil and a and [:lit, :str].include? a[0]) then
651
- submsg = a[1]
652
- in_klass m do # :task
659
+ # or s(:call, nil, :task, s(:str, "name"))
660
+ # or s(:call, nil, :task, s(:hash, s(:lit, :name) ...))
661
+
662
+ t, r, m, *a = recv
663
+
664
+ if t == :call and r == nil and submsg = dsl_name?(a) then
665
+ m = "#{m}(#{submsg})" if m and [String, Symbol].include?(submsg.class)
666
+ in_klass m do # :task/namespace
653
667
  in_method submsg, exp.file, exp.line do # :name
654
668
  process_until_empty exp
655
669
  end
data/test/test_flog.rb CHANGED
@@ -458,6 +458,57 @@ class TestFlog < MiniTest::Unit::TestCase
458
458
  util_process sexp, 2.0, :something => 1.0, :task => 1.0
459
459
  end
460
460
 
461
+ def test_process_iter_dsl_hash
462
+ # task :woot => 42 do
463
+ # something
464
+ # end
465
+
466
+ sexp = s(:iter,
467
+ s(:call, nil, :task, s(:hash, s(:lit, :woot), s(:lit, 42))),
468
+ nil,
469
+ s(:call, nil, :something))
470
+
471
+ @klass, @meth = "task", "#woot"
472
+
473
+ util_process sexp, 2.3, :something => 1.0, :task => 1.0, :lit_fixnum => 0.3
474
+ end
475
+
476
+ def test_process_iter_dsl_namespaced
477
+ # namespace :blah do
478
+ # task :woot => 42 do
479
+ # something
480
+ # end
481
+ # end
482
+
483
+ sexp = s(:iter,
484
+ s(:call, nil, :namespace, s(:lit, :blah)),
485
+ nil,
486
+ s(:iter,
487
+ s(:call, nil, :task, s(:hash, s(:lit, :woot), s(:lit, 42))),
488
+ nil,
489
+ s(:call, nil, :something)))
490
+
491
+ @klass, @meth = "namespace(blah)::task", "woot"
492
+
493
+ score = 3.3
494
+ hash = {
495
+ "namespace(blah)::task#woot" => {
496
+ :something => 1.0,
497
+ :lit_fixnum => 0.3,
498
+ :task => 1.0,
499
+ },
500
+ "namespace#blah" => {
501
+ :namespace => 1.0,
502
+ },
503
+ }
504
+
505
+ setup
506
+ @flog.process sexp
507
+
508
+ assert_equal hash, @flog.calls
509
+ assert_in_delta score, @flog.total
510
+ end
511
+
461
512
  def test_process_lit
462
513
  sexp = s(:lit, :y)
463
514
  util_process sexp, 0.0
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flog
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1937524008
4
+ hash: -2106459430
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
9
  - 0
10
10
  - b
11
- - 2
12
- version: 3.0.0.b2
11
+ - 3
12
+ version: 3.0.0.b3
13
13
  platform: ruby
14
14
  authors:
15
15
  - Ryan Davis
@@ -38,7 +38,7 @@ cert_chain:
38
38
  FBHgymkyj/AOSqKRIpXPhjC6
39
39
  -----END CERTIFICATE-----
40
40
 
41
- date: 2012-08-07 00:00:00 Z
41
+ date: 2012-10-22 00:00:00 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: sexp_processor
@@ -63,7 +63,7 @@ dependencies:
63
63
  requirements:
64
64
  - - ~>
65
65
  - !ruby/object:Gem::Version
66
- hash: -1937540908
66
+ hash: -2106476332
67
67
  segments:
68
68
  - 3
69
69
  - 0
@@ -81,11 +81,11 @@ dependencies:
81
81
  requirements:
82
82
  - - ~>
83
83
  - !ruby/object:Gem::Version
84
- hash: 1
84
+ hash: 25
85
85
  segments:
86
- - 3
87
- - 3
88
- version: "3.3"
86
+ - 4
87
+ - 1
88
+ version: "4.1"
89
89
  type: :development
90
90
  version_requirements: *id003
91
91
  - !ruby/object:Gem::Dependency
@@ -111,11 +111,11 @@ dependencies:
111
111
  requirements:
112
112
  - - ~>
113
113
  - !ruby/object:Gem::Version
114
- hash: 7
114
+ hash: 5
115
115
  segments:
116
116
  - 3
117
- - 0
118
- version: "3.0"
117
+ - 1
118
+ version: "3.1"
119
119
  type: :development
120
120
  version_requirements: *id005
121
121
  description: |-
metadata.gz.sig CHANGED
Binary file