Class: Vienna::NotFound

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

Overview

Vienna::NotFound is a default endpoint not unlike Rack::NotFound. Initialize it with the path to a 404 page and its contents will be served. The difference is that if a 404 page doesn’t exist, a default response, ‘Not Found’ will be served.

Examples

run Vienna::NotFound.new('public/404.html')

run Vienna::NotFound.new # Always return 'Not Found'

Instance Method Summary collapse

Constructor Details

#initialize(path = '') ⇒ NotFound

Returns a new instance of NotFound.



79
80
81
# File 'lib/vienna.rb', line 79

def initialize(path = '')
  @path = path
end

Instance Method Details

#bodyObject



103
104
105
# File 'lib/vienna.rb', line 103

def body
  [content]
end

#call(env) ⇒ Object



107
108
109
# File 'lib/vienna.rb', line 107

def call(env)
  [status, headers, body]
end

#contentObject



84
85
86
# File 'lib/vienna.rb', line 84

def content
  File.exist?(@path) ? File.read(@path) : 'Not Found'
end

#content_lengthObject



88
89
90
# File 'lib/vienna.rb', line 88

def content_length
  content.length.to_s
end

#headersObject



96
97
98
99
100
101
# File 'lib/vienna.rb', line 96

def headers
  {
    'Content-Type' => 'text/html',
    'Content-Length' => content_length
  }
end

#statusObject



92
93
94
# File 'lib/vienna.rb', line 92

def status
  404
end