Class: Vienna::NotFound
- Inherits:
-
Object
- Object
- Vienna::NotFound
- 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
- #body ⇒ Object
- #call(env) ⇒ Object
- #content ⇒ Object
- #content_length ⇒ Object
- #headers ⇒ Object
-
#initialize(path = '') ⇒ NotFound
constructor
A new instance of NotFound.
- #status ⇒ Object
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
#body ⇒ Object
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 |
#content ⇒ Object
84 85 86 |
# File 'lib/vienna.rb', line 84 def content File.exist?(@path) ? File.read(@path) : 'Not Found' end |
#content_length ⇒ Object
88 89 90 |
# File 'lib/vienna.rb', line 88 def content_length content.length.to_s end |
#headers ⇒ Object
96 97 98 99 100 101 |
# File 'lib/vienna.rb', line 96 def headers { 'Content-Type' => 'text/html', 'Content-Length' => content_length } end |
#status ⇒ Object
92 93 94 |
# File 'lib/vienna.rb', line 92 def status 404 end |