Skip to content

Instantly share code, notes, and snippets.

@agenteo
Created March 7, 2011 02:22
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 agenteo/857975 to your computer and use it in GitHub Desktop.
Save agenteo/857975 to your computer and use it in GitHub Desktop.
Collects the first level of routes from a file containing the 'rake routes' output.
require 'rubygems'
# Deletes standard route, standard route :format, root route
def delete_last_three_lines
3.times { @lines.delete_at(-1) } # TODO: change to .drop(3) when using Ruby 1.8.7
end
@paths = []
@lines = File.readlines('routes.txt')
@lines.delete_at(0)
delete_last_three_lines
@lines.each do |line|
line.match(/\s+\w+\s+\/([^\s][^\(](?:\w|-)*(?:\....)?)/) # match any word or - after /, terminates with {
@paths << $1
end
@paths.uniq!
puts @paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment