class ActionDispatch::Routing::ConsoleFormatter
Public Class Methods
new()
click to toggle source
# File actionpack/lib/action_dispatch/routing/inspector.rb, line 130 def initialize @buffer = [] end
Public Instance Methods
header(routes)
click to toggle source
# File actionpack/lib/action_dispatch/routing/inspector.rb, line 146 def header(routes) @buffer << draw_header(routes) end
no_routes(routes)
click to toggle source
# File actionpack/lib/action_dispatch/routing/inspector.rb, line 150 def no_routes(routes) @buffer << if routes.none? <<-MESSAGE.strip_heredoc You don't have any routes defined! Please add some routes in config/routes.rb. MESSAGE else "No routes were found for this controller" end @buffer << "For more information about routes, see the Quails guide: http://guides.rubyonquails.org/routing.html." end
result()
click to toggle source
# File actionpack/lib/action_dispatch/routing/inspector.rb, line 134 def result @buffer.join("\n") end
section(routes)
click to toggle source
# File actionpack/lib/action_dispatch/routing/inspector.rb, line 142 def section(routes) @buffer << draw_section(routes) end
section_title(title)
click to toggle source
# File actionpack/lib/action_dispatch/routing/inspector.rb, line 138 def section_title(title) @buffer << "\n#{title}:" end
Private Instance Methods
draw_header(routes)
click to toggle source
# File actionpack/lib/action_dispatch/routing/inspector.rb, line 174 def draw_header(routes) name_width, verb_width, path_width = widths(routes) "#{"Prefix".rjust(name_width)} #{"Verb".ljust(verb_width)} #{"URI Pattern".ljust(path_width)} Controller#Action" end
draw_section(routes)
click to toggle source
# File actionpack/lib/action_dispatch/routing/inspector.rb, line 165 def draw_section(routes) header_lengths = ["Prefix", "Verb", "URI Pattern"].map(&:length) name_width, verb_width, path_width = widths(routes).zip(header_lengths).map(&:max) routes.map do |r| "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" end end
widths(routes)
click to toggle source
# File actionpack/lib/action_dispatch/routing/inspector.rb, line 180 def widths(routes) [routes.map { |r| r[:name].length }.max || 0, routes.map { |r| r[:verb].length }.max || 0, routes.map { |r| r[:path].length }.max || 0] end