Class: Serve::FileTypeHandler
- Inherits:
-
Object
- Object
- Serve::FileTypeHandler
show all
- Defined in:
- lib/serve/handlers/file_type_handler.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(root_path, path) ⇒ FileTypeHandler
Returns a new instance of FileTypeHandler.
19
20
21
22
|
# File 'lib/serve/handlers/file_type_handler.rb', line 19
def initialize(root_path, path)
@root_path = root_path
@script_filename = File.join(@root_path, path)
end
|
Class Method Details
.extension(*extensions) ⇒ Object
7
8
9
10
11
|
# File 'lib/serve/handlers/file_type_handler.rb', line 7
def self.extension(*extensions)
extensions.each do |ext|
FileTypeHandler.handlers[ext] = self
end
end
|
.find(path) ⇒ Object
13
14
15
16
17
|
# File 'lib/serve/handlers/file_type_handler.rb', line 13
def self.find(path)
if ext = File.extname(path)
handlers[ext.sub(/\A\./, '')]
end
end
|
.handlers ⇒ Object
3
4
5
|
# File 'lib/serve/handlers/file_type_handler.rb', line 3
def self.handlers
@handlers ||= {}
end
|
Instance Method Details
#content_type ⇒ Object
29
30
31
|
# File 'lib/serve/handlers/file_type_handler.rb', line 29
def content_type
'text/html'
end
|
#parse(string) ⇒ Object
33
34
35
|
# File 'lib/serve/handlers/file_type_handler.rb', line 33
def parse(string)
string.dup
end
|
#process(request, response) ⇒ Object
24
25
26
27
|
# File 'lib/serve/handlers/file_type_handler.rb', line 24
def process(request, response)
response.['content-type'] = content_type
response.body = parse(open(@script_filename){|io| io.read })
end
|