Class: Router
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #draw(&proc) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #run(req, res) ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
34 35 36 |
# File 'lib/router.rb', line 34 def initialize @routes = [] end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
32 33 34 |
# File 'lib/router.rb', line 32 def routes @routes end |
Instance Method Details
#draw(&proc) ⇒ Object
38 39 40 |
# File 'lib/router.rb', line 38 def draw(&proc) self.instance_eval(&proc) end |
#run(req, res) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/router.rb', line 48 def run(req, res) matched_route = match(req) if matched_route res.status = 200 matched_route.run(req, res) else res.status = 404 end end |