Permalink
Browse files

Add option to routes task to target a specific controller with CONTRO…

…LLER=x.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#2928 state:committed]
  • Loading branch information...
1 parent 5fdc33c commit e8dc151396b6b92e243ac48b58abbe66be6f09b4 @hardbap hardbap committed with NZKoz Jul 20, 2009
Showing with 4 additions and 3 deletions.
  1. +4 −3 railties/lib/tasks/routes.rake
@@ -1,6 +1,7 @@
-desc 'Print out all defined routes in match order, with names.'
+desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
- routes = ActionController::Routing::Routes.routes.collect do |route|
+ 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|
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 }
@@ -14,4 +15,4 @@ task :routes => :environment do
routes.each do |r|
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
end
-end
+end

0 comments on commit e8dc151

Please sign in to comment.