2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-21 09:08:33 -04:00
|
|
|
require "rails/application_controller"
|
2016-08-06 13:15:47 -04:00
|
|
|
require "action_dispatch/routing/inspector"
|
2012-05-22 19:23:17 -04:00
|
|
|
|
2013-12-16 00:52:40 -05:00
|
|
|
class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
2018-06-14 04:09:00 -04:00
|
|
|
prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATH
|
2016-08-06 13:15:47 -04:00
|
|
|
layout -> { request.xhr? ? false : "application" }
|
2012-05-22 19:23:17 -04:00
|
|
|
|
2014-05-27 18:08:23 -04:00
|
|
|
before_action :require_local!
|
2012-05-22 19:23:17 -04:00
|
|
|
|
|
|
|
def index
|
2013-01-05 08:52:04 -05:00
|
|
|
redirect_to action: :routes
|
2012-05-22 19:23:17 -04:00
|
|
|
end
|
|
|
|
|
2006-03-29 10:11:47 -05:00
|
|
|
def properties
|
2019-01-08 16:21:20 -05:00
|
|
|
@info = Rails::Info.to_html
|
|
|
|
@page_title = "Properties"
|
2012-05-22 19:23:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def routes
|
2015-02-23 11:51:30 -05:00
|
|
|
if path = params[:path]
|
2020-06-27 06:19:31 -04:00
|
|
|
path = URI::DEFAULT_PARSER.escape path
|
2015-02-23 11:51:30 -05:00
|
|
|
normalized_path = with_leading_slash path
|
|
|
|
render json: {
|
2016-08-16 03:30:11 -04:00
|
|
|
exact: match_route { |it| it.match normalized_path },
|
|
|
|
fuzzy: match_route { |it| it.spec.to_s.match path }
|
2015-02-23 11:51:30 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
@routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
|
2016-08-06 13:15:47 -04:00
|
|
|
@page_title = "Routes"
|
2015-02-23 11:51:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-08-06 13:55:02 -04:00
|
|
|
def match_route
|
2021-04-26 17:55:33 -04:00
|
|
|
_routes.routes.filter_map { |route| route.path.spec.to_s if yield route.path }
|
2016-08-06 13:55:02 -04:00
|
|
|
end
|
2015-02-23 11:51:30 -05:00
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
def with_leading_slash(path)
|
|
|
|
("/" + path).squeeze("/")
|
|
|
|
end
|
2006-03-29 10:11:47 -05:00
|
|
|
end
|