Last active
October 13, 2017 10:14
-
-
Save emad-elsaid/ff6c1f5e9c560a1a7c54b50db1f6a1b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = 'Usage: ruby-methods-stats [options]... [file]...' | |
opts.on( | |
'-h', | |
'--help', | |
'Show this help text' | |
) do | |
puts opts | |
exit | |
end | |
opts.on( | |
'-sPath', | |
'--source=Path', | |
'get list of methods from this path' | |
) do |value| | |
options[:source] = value | |
end | |
opts.on( | |
'-tTarget', | |
'--target=Target', | |
'search this path for these methods' | |
) do |value| | |
options[:target] = value | |
end | |
end.parse! | |
methods_lines = `ag --ruby --nobreak --nofilename "def (self\.)?([a-z_0-9A-Z\?\!]+)" #{options[:source]}`.lines | |
methods_lines.map!(&:strip) | |
methods = methods_lines.map do |line| | |
line.match(/(?:def (?:self\.)?)(?<method>[a-z_0-9A-Z\?\!]+)/)[:method] | |
end.uniq | |
puts "Methods found: #{methods.count}" | |
stats = methods.map do |method| | |
[method, `ag -s -F --ruby --nobreak --nofilename #{method} #{options[:target]} | wc -l`.to_i] | |
end.sort_by(&:last) | |
stats.each do |k, v| | |
puts "#{k}: #{v}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment