Skip to content

Commit e8dc151

Browse files
hardbapNZKoz
authored andcommitted
Add option to routes task to target a specific controller with CONTROLLER=x.
Signed-off-by: Michael Koziarski <[email protected]> [rails#2928 state:committed]
1 parent 5fdc33c commit e8dc151

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

railties/lib/tasks/routes.rake

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
desc 'Print out all defined routes in match order, with names.'
1+
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
22
task :routes => :environment do
3-
routes = ActionController::Routing::Routes.routes.collect do |route|
3+
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
4+
routes = all_routes.collect do |route|
45
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
56
verb = route.conditions[:method].to_s.upcase
67
segs = route.segments.inject("") { |str,s| str << s.to_s }
@@ -14,4 +15,4 @@ task :routes => :environment do
1415
routes.each do |r|
1516
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
1617
end
17-
end
18+
end

0 commit comments

Comments
 (0)