zombie-killer 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45c9c420e1362bc5ed2354d40b1a7c5951530f50
4
- data.tar.gz: 8a2d7b00e756ebc906b73120c139bda02d734912
3
+ metadata.gz: 0c386e33153b7b34e0563e9359b3aa5262ee316a
4
+ data.tar.gz: 68e8158e89c4e04778126ef089dc47ee9db2b3f4
5
5
  SHA512:
6
- metadata.gz: 157976c4b7e1cc94cc8c0384b91d69bd5909eefc1ffb15569497e9fef8fff8046a5c326b9a211e703cc4192601d1ea79a977c9c3618a33370bb6ddeba1bf2922
7
- data.tar.gz: a8e31e77e9bab7316b6fac67ce1d36eafbdfb301aa60ae56f5239f3f8005e8e44bc501a3681235a62ddb449225b7609c24c867e8227cd9d1de1b617ba0f3f672
6
+ metadata.gz: 6feac8928e83b35f14a31a1f355386a823f5472ceab730b3e60fd8c1aa9fac198a6a548e4e2ae5a5d119c580f2aef973a7c9ed1cfaf99156c6606c8142b4208d
7
+ data.tar.gz: b5feb7a3335c43a141b620db9fb2c1ba647ab11a836b2022b9f9338d3e79e7fdd0562c188601baf16a27f1f7a43bc5f61fb7dbbce8cdf3eac48cd58ecd94db58
@@ -0,0 +1,76 @@
1
+ #! /usr/bin/env ruby
2
+ usage = <<'EOT'
3
+ Usage:
4
+ count_method_calls PATTERN RUBY_FILE
5
+ find -name \*.rb | count_method_calls --batch PATTERN
6
+
7
+ Where PATTERN is a shell-style pattern, for example
8
+ {Builtins,Ops}.* for all zombies
9
+ Ops.get* for all variants of `get`
10
+ *\? for queries
11
+ EOT
12
+
13
+ require "parser"
14
+ require "parser/current"
15
+
16
+ class MethodCounter < Parser::AST::Processor
17
+ def initialize(pattern)
18
+ @pattern = pattern
19
+ super()
20
+ end
21
+
22
+ def count(node)
23
+ @count = 0
24
+ process(node)
25
+ @count
26
+ end
27
+
28
+ # called by #process
29
+ def on_send(node)
30
+ super
31
+ receiver, message = *node
32
+ if receiver.nil?
33
+ method = message.to_s
34
+ else
35
+ method = "#{const_to_s(receiver)}.#{message}"
36
+ end
37
+ # extglob: {brace,alternatives}
38
+ @count += 1 if File.fnmatch(@pattern, method, File::FNM_EXTGLOB)
39
+ end
40
+
41
+ private
42
+
43
+ def const_to_s(node)
44
+ if node && node.type == :const
45
+ parent, name = *node
46
+ if parent.nil?
47
+ name.to_s
48
+ else
49
+ "#{const_to_s(parent)}.#{name}"
50
+ end
51
+ else
52
+ "%" # a non-identifier placeholder for "expression"
53
+ end
54
+ end
55
+ end
56
+
57
+ def count(pattern, filename)
58
+ buffer = Parser::Source::Buffer.new(filename).read
59
+ parser = Parser::CurrentRuby.new
60
+ ast = parser.parse(buffer)
61
+ MethodCounter.new(pattern).count(ast)
62
+ end
63
+
64
+ if ARGV[0] == "--batch"
65
+ total = 0
66
+ $stdin.each_line do |filename|
67
+ c = count(ARGV[1], filename.chomp)
68
+ total += c
69
+ printf("%5d %s", c, filename)
70
+ end
71
+ printf("%5d %s", total, "*TOTAL*")
72
+ elsif ARGV.size == 2
73
+ puts count(ARGV[0], ARGV[1])
74
+ else
75
+ $stderr.print usage
76
+ end
@@ -1,3 +1,3 @@
1
1
  class ZombieKiller
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zombie-killer
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Vidner
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-28 00:00:00.000000000 Z
12
+ date: 2014-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: docopt
@@ -99,11 +99,13 @@ email:
99
99
  - david@majda.cz
100
100
  executables:
101
101
  - zk
102
+ - count_method_calls
102
103
  extensions: []
103
104
  extra_rdoc_files: []
104
105
  files:
105
106
  - LICENSE
106
107
  - README.md
108
+ - bin/count_method_calls
107
109
  - bin/zk
108
110
  - lib/zombie_killer.rb
109
111
  - lib/zombie_killer/code_histogram.rb