Module: Clutterbuck::Router

Defined in:
lib/clutterbuck/router.rb,
lib/clutterbuck/router/route.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods Classes: MethodNotAllowedError, NotFoundError, Route

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

:nodoc: Add in the class-level methods to the app.



230
231
232
# File 'lib/clutterbuck/router.rb', line 230

def self.included(mod)
  mod.extend(ClassMethods)
end

Instance Method Details

#callObject

Handle the request.

Find the route, run it, and return the result.



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/clutterbuck/router.rb', line 246

def call
  path = env["PATH_INFO"].empty? ? "/" : env["PATH_INFO"]

  begin
    route = self.class.find_route(env["REQUEST_METHOD"], path)
  rescue Clutterbuck::Router::NotFoundError
    return [404, [["Content-Type", "text/plain"]], ["Not found"]]
  rescue Clutterbuck::Router::MethodNotAllowedError => ex
    return [405, [["Content-Type", "text/plain"]], [ex]]
  end

  route.run(self, path).tap do |response|
    if env["REQUEST_METHOD"] == "HEAD"
      response[2] = []
    end
  end
end

#initialize(env) ⇒ Object

Create a new instance of the app.

Parameters:

  • env (Hash)

    The Rack environment for this request.



238
239
240
# File 'lib/clutterbuck/router.rb', line 238

def initialize(env)
  @env = env
end