Module: Sidekiq::Web::Router
- Included in:
- Application, Application
- Defined in:
- lib/sidekiq/web/router.rb
Overview
Provides an API to declare endpoints, along with a match API to dynamically route a request to an endpoint.
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path) ⇒ Object
- #head(path) ⇒ Object
- #match(env) ⇒ Object
- #patch(path) ⇒ Object
- #post(path) ⇒ Object
- #put(path) ⇒ Object
- #route(*methods, path, &block) ⇒ Object
- #route_cache ⇒ Object
Instance Method Details
#delete(path) ⇒ Object
20 |
# File 'lib/sidekiq/web/router.rb', line 20 def delete(path, &) = route(:delete, path, &) |
#get(path) ⇒ Object
12 |
# File 'lib/sidekiq/web/router.rb', line 12 def get(path, &) = route(:get, path, &) |
#head(path) ⇒ Object
10 |
# File 'lib/sidekiq/web/router.rb', line 10 def head(path, &) = route(:head, path, &) |
#match(env) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sidekiq/web/router.rb', line 29 def match(env) request_method = env["REQUEST_METHOD"].downcase.to_sym path_info = ::Rack::Utils.unescape_path 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 == "" route_cache[request_method].each do |route| params = route.match(request_method, path_info) if params env["rack.route_params"] = params return Action.new(env, route.block) end end nil end |
#patch(path) ⇒ Object
18 |
# File 'lib/sidekiq/web/router.rb', line 18 def patch(path, &) = route(:patch, path, &) |
#post(path) ⇒ Object
14 |
# File 'lib/sidekiq/web/router.rb', line 14 def post(path, &) = route(:post, path, &) |
#put(path) ⇒ Object
16 |
# File 'lib/sidekiq/web/router.rb', line 16 def put(path, &) = route(:put, path, &) |
#route(*methods, path, &block) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/sidekiq/web/router.rb', line 22 def route(*methods, path, &block) methods.each do |method| raise ArgumentError, "Invalid method #{method}. Must be one of #{@routes.keys.join(",")}" unless route_cache.has_key?(method) route_cache[method] << Route.new(method, path, block) end end |
#route_cache ⇒ Object
48 49 50 |
# File 'lib/sidekiq/web/router.rb', line 48 def route_cache @@routes ||= {get: [], post: [], put: [], patch: [], delete: [], head: []} end |