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
|
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
|
|
|
|
verb = route.conditions[:method].to_s.upcase
|
|
|
|
segs = route.segments.inject("") { |str,s| str << s.to_s }
|
2007-06-28 14:44:08 -04:00
|
|
|
segs.chop! if segs.length > 1
|
2007-06-28 14:33:06 -04:00
|
|
|
reqs = route.requirements.empty? ? "" : route.requirements.inspect
|
|
|
|
{:name => name, :verb => verb, :segs => segs, :reqs => reqs}
|
|
|
|
end
|
|
|
|
name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
|
|
|
|
verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
|
|
|
|
segs_width = routes.collect {|r| r[:segs]}.collect {|s| s.length}.max
|
|
|
|
routes.each do |r|
|
|
|
|
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
|
|
|
|
end
|
2009-07-20 16:48:08 -04:00
|
|
|
end
|