diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-06-28 18:33:06 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-06-28 18:33:06 +0000 |
commit | f6a91b7b4ce2a7767392dfd3414a098047205c10 (patch) | |
tree | 1a044e34da51ea48279fd6de497680ee55aa832a | |
parent | dfc15e122afcc7e3cfabaadfbac639af7e846b5a (diff) | |
download | rails-f6a91b7b4ce2a7767392dfd3414a098047205c10.tar.gz rails-f6a91b7b4ce2a7767392dfd3414a098047205c10.tar.bz2 rails-f6a91b7b4ce2a7767392dfd3414a098047205c10.zip |
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
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/lib/tasks/routes.rake | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 283a67ed29..466d922f70 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -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] diff --git a/railties/lib/tasks/routes.rake b/railties/lib/tasks/routes.rake new file mode 100644 index 0000000000..bb9971b717 --- /dev/null +++ b/railties/lib/tasks/routes.rake @@ -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
\ No newline at end of file |