aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Breen <hardbap@gmail.com>2009-07-20 16:48:08 -0400
committerMichael Koziarski <michael@koziarski.com>2009-08-08 14:38:33 +1200
commite8dc151396b6b92e243ac48b58abbe66be6f09b4 (patch)
tree04b2b0b239f7675258a241a8f7ae7984e2f7690f
parent5fdc33c1a37b4c321135753ed546e8afc2dbaf3e (diff)
downloadrails-e8dc151396b6b92e243ac48b58abbe66be6f09b4.tar.gz
rails-e8dc151396b6b92e243ac48b58abbe66be6f09b4.tar.bz2
rails-e8dc151396b6b92e243ac48b58abbe66be6f09b4.zip
Add option to routes task to target a specific controller with CONTROLLER=x.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#2928 state:committed]
-rw-r--r--railties/lib/tasks/routes.rake7
1 files changed, 4 insertions, 3 deletions
diff --git a/railties/lib/tasks/routes.rake b/railties/lib/tasks/routes.rake
index 39b7139167..abbf3258c1 100644
--- a/railties/lib/tasks/routes.rake
+++ b/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 \ No newline at end of file
+end