Class: Rollerskates::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/rollerskates/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



5
6
7
# File 'lib/rollerskates/application.rb', line 5

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

Instance Attribute Details

#routesObject (readonly)

Returns the value of attribute routes.



3
4
5
# File 'lib/rollerskates/application.rb', line 3

def routes
  @routes
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/rollerskates/application.rb', line 9

def call(env)
  @request = Rack::Request.new(env)
  route = mapper.map_to_route(@request)
  if route
    response = route.dispatch
    return response.finish(route.method_name)
  end
  [404, {}, ["Route not found"]]
end

#mapperObject



19
20
21
# File 'lib/rollerskates/application.rb', line 19

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