Created
July 20, 2009 20:23
-
-
Save jacobat/150879 to your computer and use it in GitHub Desktop.
Quick'n'dirty script for figuring out which methods are unused in a Rails project
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 | |
grep_result = `grep -ri "def " #{ARGV.join(' ')}` | |
methods = grep_result.split("\n").collect do |line| | |
md = line.match(/.*:\s+def ([a-z_]+)(\((.*)\))?/i) | |
md.to_a[1] | |
end | |
filtered_methods = methods.uniq - ["initialize"] | |
dirs = (Dir.glob("*") - ['vendor', 'log']).join(" ") | |
filtered_methods.each do |method_name| | |
cmd = "grep -ri #{method_name} #{dirs}" | |
lines = `#{cmd}` | |
puts "#{method_name} only found once" if lines.split("\n").size < 2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment