Class: Lifer::Dev::Router

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

Overview

The dev router is responsible for routing requests from the ‘Lifer::Dev:Server`. Note that in production, the dev server would never be used. So the dev router does not need to be very sophisticated.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build_directory:) ⇒ void

Builds an instance of the router. In development mode, we’d expect only one router to be initialized, but in test mode, there’d be a new one for each test.

Parameters:

  • build_directory (String)

    The path to the Lifer output directory (i.e. ‘/path/to/_build`).



18
19
20
# File 'lib/lifer/dev/router.rb', line 18

def initialize(build_directory:)
  @build_directory = build_directory
end

Instance Attribute Details

#build_directoryObject

Returns the value of attribute build_directory.



9
10
11
# File 'lib/lifer/dev/router.rb', line 9

def build_directory
  @build_directory
end

Instance Method Details

#response_for(request_env) ⇒ Lifer::Dev::Response

Give a Rack request env object, return a Rack-compatible response.

Parameters:

  • request_env (Hash)

    A Rack request env object.

Returns:



26
27
28
29
30
# File 'lib/lifer/dev/router.rb', line 26

def response_for(request_env)
  local_path = local_path_to request_env["PATH_INFO"]

  Lifer::Dev::Response.new(local_path).build
end