Class: Mgt::Application

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



16
17
18
# File 'lib/mgt.rb', line 16

def initialize
  @routes = Routing::Router.new
end

Instance Attribute Details

#routesObject (readonly)

Returns the value of attribute routes.



14
15
16
# File 'lib/mgt.rb', line 14

def routes
  @routes
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/mgt.rb', line 20

def call(env)
  @request = Rack::Request.new(env)
  route = mapper.map_to_route(@request)

  if route
    route.dispatch
  else
    [404, {}, ["Page not found"]]
  end
end

#mapperObject



31
32
33
# File 'lib/mgt.rb', line 31

def mapper
  @mapper ||= Routing::Mapper.new(routes.endpoints)
end