Class: Rack::WebProfiler::Router
- Inherits:
-
Object
- Object
- Rack::WebProfiler::Router
- Defined in:
- lib/rack/web_profiler/router.rb
Overview
Router
Show WebProfiler page if the request path match with one of the webprofiler routes.
Constant Summary collapse
- BASE_PATH =
"/_rwpt".freeze
Class Method Summary collapse
-
.response_for(request) ⇒ Rack::Reponse, false
Get response for given request.
-
.route(request, path) ⇒ Rack::Reponse, false
Route the request.
-
.serve_asset(path) ⇒ Rack::Response
Serve assets.
-
.url_for_asset(path) ⇒ String
Get url for asset.
-
.url_for_clean_profiler ⇒ String
Get url to clean webprofiler.
-
.url_for_profiler(token = nil, panel = nil) ⇒ String
Get url for the webprofiler.
-
.url_for_toolbar(token) ⇒ String
Get url for toobar.
Class Method Details
.response_for(request) ⇒ Rack::Reponse, false
Get response for given request.
15 16 17 18 19 20 21 22 23 24 25 26 |
# 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) ⇒ Rack::Reponse, false
Route the request.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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.(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) ⇒ Rack::Response
Serve assets.
57 58 59 60 61 62 63 64 65 |
# File 'lib/rack/web_profiler/router.rb', line 57 def serve_asset(path) rf = Rack::File.new(::File.("../../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) ⇒ String
Get url for asset.
72 73 74 |
# File 'lib/rack/web_profiler/router.rb', line 72 def url_for_asset(path) "#{get_base_path}/assets/#{path}" end |
.url_for_clean_profiler ⇒ String
Get url to clean webprofiler.
100 101 102 |
# 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) ⇒ String
Get url for the webprofiler.
91 92 93 94 95 |
# 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) ⇒ String
Get url for toobar.
81 82 83 |
# File 'lib/rack/web_profiler/router.rb', line 81 def (token) "#{get_base_path}/toolbar/#{token}" end |