diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2018-03-13 20:51:29 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2018-03-13 20:56:37 +0100 |
commit | 6629d51a2756fadf961bb09df20579cacfef2c8e (patch) | |
tree | 046606294f0d861afda7886bb75b5e7ad1c311d2 /actionpack/lib/action_dispatch | |
parent | f6310a3f163d565cfc014143212e5ee2f0f2ae79 (diff) | |
download | rails-6629d51a2756fadf961bb09df20579cacfef2c8e.tar.gz rails-6629d51a2756fadf961bb09df20579cacfef2c8e.tar.bz2 rails-6629d51a2756fadf961bb09df20579cacfef2c8e.zip |
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.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/inspector.rb | 47 |
1 files changed, 21 insertions, 26 deletions
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 <a href="http://guides.rubyonrails.org/routing.html">Rails Routing from the Outside In</a>. </li> </ul> - MESSAGE + MESSAGE end def result |