From 193e4de20646a025bf6dd3f90d1f9a53edb1cecf Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Fri, 15 Jul 2011 01:54:59 +0800 Subject: Better formatting of route requirements in rake:routes. Previously it was: {:controller=>"photos", :action=>"show", :id=>/[A-Z]\d{5}/} Now it becomes: photos#show {:id=>/[A-Z]\d{5}/} --- railties/lib/rails/tasks/routes.rake | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/tasks') diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index a0c953967c..adc005769f 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -11,7 +11,15 @@ task :routes => :environment do reqs = route.requirements.dup reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ - reqs = reqs.empty? ? "" : reqs.inspect + + controller_action = "#{reqs[:controller]}##{reqs[:action]}" + constraints = reqs.except(:controller, :action) + + reqs = controller_action == '#' ? '' : controller_action + + unless constraints.empty? + reqs = reqs.empty? ? constraints.inspect : "#{reqs} #{constraints.inspect}" + end {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs} end -- cgit v1.2.3 From 7b619f1d7b3d261918592d4a9144d4a5d335d4b0 Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Sun, 17 Jul 2011 00:16:40 +0800 Subject: Improve formatting of route to Rack application in rake routes. This route: match 'foo/:id' => RackApp, :id => /[A-Z]\d{5}/ is shown as: /foo/:id(.:format) RackApp {:id=>/[A-Z]\d{5}/} --- railties/lib/rails/tasks/routes.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/lib/rails/tasks') diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index adc005769f..0c26bcf790 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -10,12 +10,12 @@ task :routes => :environment do routes = all_routes.collect do |route| reqs = route.requirements.dup - reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ + rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ - controller_action = "#{reqs[:controller]}##{reqs[:action]}" + endpoint = rack_app ? rack_app.inspect : "#{reqs[:controller]}##{reqs[:action]}" constraints = reqs.except(:controller, :action) - reqs = controller_action == '#' ? '' : controller_action + reqs = endpoint == '#' ? '' : endpoint unless constraints.empty? reqs = reqs.empty? ? constraints.inspect : "#{reqs} #{constraints.inspect}" -- cgit v1.2.3