Class: IrcMachine::HttpRouter
- Inherits:
-
Object
- Object
- IrcMachine::HttpRouter
- Includes:
- CoreRoutes
- Defined in:
- lib/irc_machine/http_router.rb
Instance Method Summary collapse
- #connect(method, pattern, destination) ⇒ Object
- #delete(route, destination) ⇒ Object
- #get(route, destination) ⇒ Object
-
#initialize(session) ⇒ HttpRouter
constructor
A new instance of HttpRouter.
- #post(route, destination) ⇒ Object
- #put(route, destination) ⇒ Object
- #route(env) ⇒ Object
Methods included from CoreRoutes
Constructor Details
#initialize(session) ⇒ HttpRouter
Returns a new instance of HttpRouter.
9 10 11 12 13 |
# File 'lib/irc_machine/http_router.rb', line 9 def initialize(session) @session = session @routes = { get: [], put: [], delete:[], post: [] } draw_routes end |
Instance Method Details
#connect(method, pattern, destination) ⇒ Object
44 45 46 |
# File 'lib/irc_machine/http_router.rb', line 44 def connect(method, pattern, destination) @routes[method] << [ pattern, destination ] end |
#delete(route, destination) ⇒ Object
41 |
# File 'lib/irc_machine/http_router.rb', line 41 def delete(route, destination); connect :delete, route, destination; end |
#get(route, destination) ⇒ Object
39 |
# File 'lib/irc_machine/http_router.rb', line 39 def get(route, destination); connect :get, route, destination; end |
#post(route, destination) ⇒ Object
42 |
# File 'lib/irc_machine/http_router.rb', line 42 def post(route, destination); connect :post, route, destination; end |
#put(route, destination) ⇒ Object
40 |
# File 'lib/irc_machine/http_router.rb', line 40 def put(route, destination); connect :put, route, destination; end |
#route(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/irc_machine/http_router.rb', line 15 def route(env) request = Rack::Request.new(env) match = lookup_route_match(request.request_method, request.path) puts "%s %s %s => %s" % [ self.class, request.request_method, request.path, match.destination.inspect ] response = case match.destination when String name, method = match.destination.split("#") klass = IrcMachine::Controller.const_get(name) klass.dispatch(@session, request, method, match.match) else Rack::Response.new "Unhandled destination: #{match.destination.class}", 500 end response.finish end |