Class: Lanyon::Application

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

Overview

Rack application that serves the Jekyll site.

Not to be instantiated directly, use Lanyon.application instead.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router) ⇒ Application

Returns a new instance of Application.



18
19
20
# File 'lib/lanyon/application.rb', line 18

def initialize(router)
  @router = router
end

Instance Attribute Details

#routerObject (readonly)

Returns the value of attribute router.



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

def router
  @router
end

Instance Method Details

#call(env) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lanyon/application.rb', line 22

def call(env)
  request = Rack::Request.new(env)
  endpoint = router.endpoint(request.path_info)

  case endpoint
  when :not_found
    not_found_response
  when :must_redirect
    redirect_to_dir_response(request.path_info)
  else
    case request.request_method
    when "HEAD", "GET"
      response(endpoint)
    when "OPTIONS"
      [200, { "Allow" => "GET,HEAD,OPTIONS", "Content-Length" => "0" }, []]
    else
      not_allowed_response
    end
  end
end