From 6629d51a2756fadf961bb09df20579cacfef2c8e Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 13 Mar 2018 20:51:29 +0100 Subject: Rely on Rails::Command's help output. We end up with: ``` Usage: bin/rails routes [options] Options: -c, [--controller=CONTROLLER] # Filter by a specific controller, e.g. PostsController or Admin::PostsController. -g, [--grep=GREP] # Grep routes by a specific pattern. -E, [--expanded], [--no-expanded] # Print routes expanded vertically with parts explained. ``` which does miss the bit about routes being printed in order. Also: * Renames options to ease help output readability, then clarifies each option. * Fixes a bunch of indentation. --- .../lib/action_dispatch/routing/inspector.rb | 47 ++++++++++------------ 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing/inspector.rb') diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb index 7656c263a3..bae50f6a43 100644 --- a/actionpack/lib/action_dispatch/routing/inspector.rb +++ b/actionpack/lib/action_dispatch/routing/inspector.rb @@ -81,18 +81,12 @@ module ActionDispatch end private - def normalize_filter(filter) if filter[:controller] { controller: /#{filter[:controller].downcase.sub(/_?controller\z/, '').sub('::', '/')}/ } - elsif filter[:grep_pattern] - { - controller: /#{filter[:grep_pattern]}/, - action: /#{filter[:grep_pattern]}/, - verb: /#{filter[:grep_pattern]}/, - name: /#{filter[:grep_pattern]}/, - path: /#{filter[:grep_pattern]}/ - } + elsif filter[:grep] + { controller: /#{filter[:grep]}/, action: /#{filter[:grep]}/, + verb: /#{filter[:grep]}/, name: /#{filter[:grep]}/, path: /#{filter[:grep]}/ } end end @@ -153,17 +147,18 @@ module ActionDispatch def no_routes(routes, filter) @buffer << - if routes.none? - <<~MESSAGE - You don't have any routes defined! - - Please add some routes in config/routes.rb. - MESSAGE - elsif filter.has_key?(:controller) - "No routes were found for this controller." - elsif filter.has_key?(:grep_pattern) - "No routes were found for this grep pattern." - end + if routes.none? + <<~MESSAGE + You don't have any routes defined! + + Please add some routes in config/routes.rb. + MESSAGE + elsif filter.key?(:controller) + "No routes were found for this controller." + elsif filter.key?(:grep) + "No routes were found for this grep pattern." + end + @buffer << "For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html." end end @@ -219,11 +214,11 @@ module ActionDispatch def draw_expanded_section(routes) routes.map.each_with_index do |r, i| <<~MESSAGE.chomp - #{route_header(index: i + 1)} - Prefix | #{r[:name]} - Verb | #{r[:verb]} - URI | #{r[:path]} - Controller#Action | #{r[:reqs]} + #{route_header(index: i + 1)} + Prefix | #{r[:name]} + Verb | #{r[:verb]} + URI | #{r[:path]} + Controller#Action | #{r[:reqs]} MESSAGE end end @@ -266,7 +261,7 @@ module ActionDispatch Rails Routing from the Outside In. - MESSAGE + MESSAGE end def result -- cgit v1.2.3