mirror of
https://github.com/github/rails.git
synced 2026-01-31 01:08:19 -05:00
Added rake routes for listing all the defined routes in the system (closes #8795) [josh]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7149 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Added rake routes for listing all the defined routes in the system #8795 [josh]
|
||||
|
||||
* db:create creates the database for the current environment if it's on localhost. db:create:all creates local databases for all environments. #8783 [matt]
|
||||
|
||||
* Generators: look for generators in all gems, not just those suffixed with _generator, in the gem's generators or rails_generators directory. Allow use of the rails_generators directory instead of the standard generators directory in plugins also. #8730 [Dr Nic, topfunky]
|
||||
|
||||
16
railties/lib/tasks/routes.rake
Normal file
16
railties/lib/tasks/routes.rake
Normal file
@@ -0,0 +1,16 @@
|
||||
desc 'Print out all defined routes in match order, with names.'
|
||||
task :routes => :environment do
|
||||
routes = ActionController::Routing::Routes.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 }
|
||||
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
|
||||
end
|
||||
Reference in New Issue
Block a user