[Rails] find not used partial ruby script

find_partial_not_used.rb
 

def string_between_markers string, marker1, marker2
  string[/#{Regexp.escape(marker1)}(.*?)#{Regexp.escape(marker2)}/m, 1]
end

all_erb_files=`find . -name '_*.erb'`.split("\n")
short_names = all_erb_files.collect {|f|
  string_between_markers f, "/_", "."
}.uniq
short_names.each {|s|
  how_many_times_is_called=`find . -name *.erb | xargs grep render | grep #{s} | wc -l`
  puts "partial #{s} not rendered in any file" if how_many_times_is_called.to_i == 0
}

Nessun commento: