Skip to content

Instantly share code, notes, and snippets.

@mlankenau
Created June 26, 2015 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlankenau/1b49a6812c4a9ed99ab7 to your computer and use it in GitHub Desktop.
Save mlankenau/1b49a6812c4a9ed99ab7 to your computer and use it in GitHub Desktop.
ruby script that is searching for invalid url/path helper in an rails project
#
# script is searching for all the url and path helpers that does not exist
#
search_result = `egrep -o -r "([a-z][a-z]+_){2,10}(path|url)" app`
routes = `rake routes`
def without_path(name)
name.split('_')[0..-2].join('_')
end
helpers = search_result.split("\n").map { |l| l.split(':').last}.compact.uniq
valid_names = routes.split("\n").map { |l| (l =~ /^\s*([a-z_]+)\s*[A-Z\|]+/) ? $1 : nil }.compact
bad_helpers = helpers.select { |h| !valid_names.include?(without_path(h)) }
bad_helpers.each { |h| puts h}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment