mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
c81af6ae72
We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
45 lines
1.1 KiB
Ruby
45 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails/application_controller"
|
|
require "action_dispatch/routing/inspector"
|
|
|
|
class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATH
|
|
layout -> { request.xhr? ? false : "application" }
|
|
|
|
before_action :require_local!
|
|
|
|
def index
|
|
redirect_to action: :routes
|
|
end
|
|
|
|
def properties
|
|
@info = Rails::Info.to_html
|
|
@page_title = "Properties"
|
|
end
|
|
|
|
def routes
|
|
if path = params[:path]
|
|
path = URI.parser.escape path
|
|
normalized_path = with_leading_slash path
|
|
render json: {
|
|
exact: match_route { |it| it.match normalized_path },
|
|
fuzzy: match_route { |it| it.spec.to_s.match path }
|
|
}
|
|
else
|
|
@routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
|
|
@page_title = "Routes"
|
|
end
|
|
end
|
|
|
|
private
|
|
def match_route
|
|
_routes.routes.select { |route|
|
|
yield route.path
|
|
}.map { |route| route.path.spec.to_s }
|
|
end
|
|
|
|
def with_leading_slash(path)
|
|
("/" + path).squeeze("/")
|
|
end
|
|
end
|