From f6a91b7b4ce2a7767392dfd3414a098047205c10 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 28 Jun 2007 18:33:06 +0000 Subject: 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 --- railties/CHANGELOG | 2 ++ railties/lib/tasks/routes.rake | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 railties/lib/tasks/routes.rake 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 -- cgit v1.2.3