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!
|
2010-02-23 20:56:28 -05:00
|
|
|
all_routes = ENV['CONTROLLER'] ? Rails.application.routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : Rails.application.routes.routes
|
2009-07-20 16:48:08 -04:00
|
|
|
routes = all_routes.collect do |route|
|
2010-02-23 20:56:28 -05:00
|
|
|
name = Rails.application.routes.named_routes.routes.index(route).to_s
|
2007-06-28 14:33:06 -04:00
|
|
|
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
|