Module: Sidekiq::WebRouter
- Included in:
- WebApplication
- Defined in:
- lib/sidekiq/web/router.rb
Constant Summary collapse
- GET =
"GET"
- DELETE =
"DELETE"
- POST =
"POST"
- PUT =
"PUT"
- PATCH =
"PATCH"
- HEAD =
"HEAD"
- ROUTE_PARAMS =
"rack.route_params"
- REQUEST_METHOD =
"REQUEST_METHOD"
- PATH_INFO =
"PATH_INFO"
Instance Method Summary collapse
- #delete(path, &block) ⇒ Object
- #get(path, &block) ⇒ Object
- #head(path, &block) ⇒ Object
- #match(env) ⇒ Object
- #patch(path, &block) ⇒ Object
- #post(path, &block) ⇒ Object
- #put(path, &block) ⇒ Object
- #route(*methods, path, &block) ⇒ Object
Instance Method Details
#delete(path, &block) ⇒ Object
38 39 40 |
# File 'lib/sidekiq/web/router.rb', line 38 def delete(path, &block) route(DELETE, path, &block) end |
#get(path, &block) ⇒ Object
22 23 24 |
# File 'lib/sidekiq/web/router.rb', line 22 def get(path, &block) route(GET, path, &block) end |
#head(path, &block) ⇒ Object
18 19 20 |
# File 'lib/sidekiq/web/router.rb', line 18 def head(path, &block) route(HEAD, path, &block) end |
#match(env) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sidekiq/web/router.rb', line 51 def match(env) request_method = env[REQUEST_METHOD] path_info = ::Rack::Utils.unescape env[PATH_INFO] # There are servers which send an empty string when requesting the root. # These servers should be ashamed of themselves. path_info = "/" if path_info == "" @routes[request_method].each do |route| params = route.match(request_method, path_info) if params env[ROUTE_PARAMS] = params return WebAction.new(env, route.block) end end nil end |
#patch(path, &block) ⇒ Object
34 35 36 |
# File 'lib/sidekiq/web/router.rb', line 34 def patch(path, &block) route(PATCH, path, &block) end |
#post(path, &block) ⇒ Object
26 27 28 |
# File 'lib/sidekiq/web/router.rb', line 26 def post(path, &block) route(POST, path, &block) end |
#put(path, &block) ⇒ Object
30 31 32 |
# File 'lib/sidekiq/web/router.rb', line 30 def put(path, &block) route(PUT, path, &block) end |
#route(*methods, path, &block) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/sidekiq/web/router.rb', line 42 def route(*methods, path, &block) @routes ||= {GET => [], POST => [], PUT => [], PATCH => [], DELETE => [], HEAD => []} methods.each do |method| method = method.to_s.upcase @routes[method] << WebRoute.new(method, path, block) end end |