Class: Router

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRouter

Returns a new instance of Router.



34
35
36
# File 'lib/router.rb', line 34

def initialize
  @routes = []
end

Instance Attribute Details

#routesObject (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