2009-07-20 16:48:08 -04:00
|
|
|
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
|
2007-06-28 14:33:06 -04:00
|
|
|
task :routes => :environment do
|
2010-01-24 05:06:06 -05:00
|
|
|
Rails::Application.reload_routes!
|
2009-07-20 16:48:08 -04:00
|
|
|
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
|
|
|
|
routes = all_routes.collect do |route|
|
2007-06-28 14:33:06 -04:00
|
|
|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
|
|
|
|
reqs = route.requirements.empty? ? "" : route.requirements.inspect
|
2009-10-24 19:08:54 -04:00
|
|
|
{:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
|
2007-06-28 14:33:06 -04:00
|
|
|
end
|
2010-01-27 10:46:59 -05:00
|
|
|
routes.reject!{ |r| r[:path] == "/rails/info/properties" } # skip the route if it's internal info route
|
2007-06-28 14:33:06 -04:00
|
|
|
name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
|
|
|
|
verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
|
2009-10-24 19:08:54 -04:00
|
|
|
path_width = routes.collect {|r| r[:path]}.collect {|s| s.length}.max
|
2007-06-28 14:33:06 -04:00
|
|
|
routes.each do |r|
|
2009-10-24 19:08:54 -04:00
|
|
|
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
|
2007-06-28 14:33:06 -04:00
|
|
|
end
|
2009-07-20 16:48:08 -04:00
|
|
|
end
|