diff options
author | bogdanvlviv <bogdanvlviv@gmail.com> | 2018-03-03 15:50:01 +0200 |
---|---|---|
committer | bogdanvlviv <bogdanvlviv@gmail.com> | 2018-03-05 14:56:59 +0200 |
commit | 012a4a3842db66b5fc6b190cb61d4d845d1cd527 (patch) | |
tree | 83173fb82595ba340bea4a378741713acfd2e145 /actionpack/lib | |
parent | ae2d36cf21281f4b720332a086b021d867e80084 (diff) | |
download | rails-012a4a3842db66b5fc6b190cb61d4d845d1cd527.tar.gz rails-012a4a3842db66b5fc6b190cb61d4d845d1cd527.tar.bz2 rails-012a4a3842db66b5fc6b190cb61d4d845d1cd527.zip |
Draw line of a route name to the end of row console on `rails routes --expanded`
In order to get width of console use `IO::console_size`,
See https://ruby-doc.org/stdlib-2.4.1/libdoc/io/console/rdoc/IO.html#method-c-console_size
Related to #32130
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/inspector.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb index de200fada0..19dfb44283 100644 --- a/actionpack/lib/action_dispatch/routing/inspector.rb +++ b/actionpack/lib/action_dispatch/routing/inspector.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "delegate" +require "io/console/size" module ActionDispatch module Routing @@ -225,7 +226,7 @@ module ActionDispatch def draw_expanded_section(routes) routes.map.each_with_index do |r, i| <<~MESSAGE - --[ Route #{i + 1} ]#{'-' * 60} + #{route_header(index: i + 1)} Prefix | #{r[:name]} Verb | #{r[:verb]} URI | #{r[:path]} @@ -233,6 +234,14 @@ module ActionDispatch MESSAGE end end + + def route_header(index:) + console_width = IO.console_size.second + header_prefix = "--[ Route #{index} ]" + dash_remainder = [console_width - header_prefix.size, 0].max + + "#{header_prefix}#{'-' * dash_remainder}" + end end end |