class Rack::WebProfiler::Router
Show WebProfiler
page if the request path match with one of the webprofiler routes.
Constants
- BASE_PATH
Public Class Methods
response_for(request)
click to toggle source
Get response for given request.
@param request [Rack::WebProfiler::Request]
@return [Rack::Reponse, false]
# File lib/rack/web_profiler/router.rb, line 15 def response_for(request) @request = request path = Rack::Utils.unescape(request.path_info) # Stop process if the request path does not start # by the BASE_PATH. return false unless path.start_with?(BASE_PATH) path.slice!(BASE_PATH) route(request, path) end
route(request, path)
click to toggle source
Route the request.
@param request [Rack::WebProfiler::Request] @param path [String]
@return [Rack::Reponse, false]
# File lib/rack/web_profiler/router.rb, line 34 def route(request, path) controller = WebProfiler::Controller.new(request) if request.get? && path =~ %r{^\/assets\/(.*)(\/)?$} serve_asset(Regexp.last_match(1)) elsif request.get? && path =~ %r{^\/toolbar\/([a-z0-9]*)(\/)?$} controller.show_toolbar(Regexp.last_match(1)) elsif request.get? && path =~ %r{^\/clean(\/)?$} controller.delete elsif request.get? && path =~ %r{^(\/)?$} controller.index elsif request.get? && path =~ %r{^\/([a-z0-9]*)(\/)?$} controller.show(Regexp.last_match(1)) else false end end
serve_asset(path)
click to toggle source
Serve assets.
@param path [String]
@return [Rack::Response]
# File lib/rack/web_profiler/router.rb, line 57 def serve_asset(path) rf = Rack::File.new(::File.expand_path("../../templates/assets/", __FILE__)) request = @request.dup request.env[PATH_INFO] = "/#{path}" status, headers, body = rf.call(request.env) Rack::Response.new(body, status, headers) end
url_for_asset(path)
click to toggle source
Get url for asset.
@param path [String]
@return [String]
# File lib/rack/web_profiler/router.rb, line 72 def url_for_asset(path) "#{get_base_path}/assets/#{path}" end
url_for_clean_profiler()
click to toggle source
Get url to clean webprofiler.
@return [String]
# File lib/rack/web_profiler/router.rb, line 100 def url_for_clean_profiler "#{get_base_path}/clean" end
url_for_profiler(token = nil, panel = nil)
click to toggle source
Get url for the webprofiler.
@param token [String, nil] @param panel [String, nil]
@return [String]
# File lib/rack/web_profiler/router.rb, line 91 def url_for_profiler(token = nil, panel = nil) query = "" query = "?panel=#{panel}" unless panel.nil? "#{get_base_path}/#{token}#{query}" end
url_for_toolbar(token)
click to toggle source
Get url for toobar.
@param token [String]
@return [String]
# File lib/rack/web_profiler/router.rb, line 81 def url_for_toolbar(token) "#{get_base_path}/toolbar/#{token}" end
Private Class Methods
get_base_path()
click to toggle source
# File lib/rack/web_profiler/router.rb, line 106 def get_base_path "#{@request.env["ORIGINAL_SCRIPT_NAME"]}#{BASE_PATH}" end