-
-
Save johana-star/5062975 to your computer and use it in GitHub Desktop.
I tried to simplify this, but man, I don't know if I can crush down these conditionals and enumerables.
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
namespace :cleaner do | |
task :find do | |
models = Dir.glob("app/models/**/*") | |
methods = %w[] | |
models.each do |model| | |
if File.file?(model) | |
File.open(model).lines.each do |line| | |
if method = method_name? line | |
methods << method | |
end | |
end | |
end | |
end | |
all_files = Dir.glob("app/**/*") | |
methods.each do |method| | |
use_count = 0 | |
all_files.each do |file| | |
if File.file?(file) | |
begin # Hack to handle binary files. | |
file_count = File.readlines(file).grep(Regexp.new(method)).size | |
rescue | |
use_count += file_count unless file_count.nil? | |
end | |
puts "#{method} is a candidate for deletion" if use_count == 1 | |
end | |
end | |
end | |
end | |
protected | |
def method_name?(line) | |
if line.match(/def ([a-z0-9._?!]*)/) | |
line.match(/def (?:self.)?([a-z0-9._?!]*)/)[1] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment