Class: Aho::WebServer::Router
- Inherits:
-
Object
- Object
- Aho::WebServer::Router
- Defined in:
- lib/aho/web_server/router.rb
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #route_for(env) ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
8 9 10 |
# File 'lib/aho/web_server/router.rb', line 8 def initialize @routes = Hash.new { |hash, key| hash[key] = {} } end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
6 7 8 |
# File 'lib/aho/web_server/router.rb', line 6 def routes @routes end |
Instance Method Details
#route_for(env) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/aho/web_server/router.rb', line 12 def route_for(env) path = env['PATH_INFO'] method = env['REQUEST_METHOD'].downcase destination = routes.dig(method.to_sym, path) return if destination.nil? controller = Module.const_get(destination[:controller]).new(env) controller.public_send(destination[:action]) end |