2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-30 00:55:31 -04:00
|
|
|
require_relative "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:
|
2012-12-17 15:26:46 -05:00
|
|
|
prepend_view_path ActionDispatch::DebugExceptions::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
|
2012-05-22 19:23:17 -04:00
|
|
|
@info = Rails::Info.to_html
|
2016-08-06 13:15:47 -04:00
|
|
|
@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]
|
2015-05-05 00:13:15 -04:00
|
|
|
path = URI.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
|
2016-08-16 03:30:11 -04:00
|
|
|
_routes.routes.select { |route|
|
2016-08-06 13:55:02 -04:00
|
|
|
yield route.path
|
2016-08-16 03:30:11 -04:00
|
|
|
}.map { |route| route.path.spec.to_s }
|
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
|