Created
June 26, 2015 06:32
-
-
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
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
# | |
# 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