Class: PicklesHttpServer::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/pickles_http/router.rb

Instance Method Summary collapse

Constructor Details

#initializeRouter

Returns a new instance of Router.



3
4
5
# File 'lib/pickles_http/router.rb', line 3

def initialize()
  @routes = {}
end

Instance Method Details

#add_route(method, path, handler) ⇒ Object



7
8
9
10
11
# File 'lib/pickles_http/router.rb', line 7

def add_route(method, path, handler)
  method = method.upcase
  @routes[method] ||= {}
  @routes[method][path] = handler
end

#route_request(method, path) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/pickles_http/router.rb', line 13

def route_request(method, path)
  method = method.upcase
  return nil unless @routes[method]

  handler = @routes[method][path]
  return nil unless handler

  handler
end