Class: Dope::StaticFileHandler
- Inherits:
-
Derailleur::RackHandler
- Object
- Derailleur::RackHandler
- Dope::StaticFileHandler
show all
- Defined in:
- lib/dope/core/handler.rb
Defined Under Namespace
Classes: NoSuchStaticFile
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.registrations ⇒ Object
Returns the value of attribute registrations.
14
15
16
|
# File 'lib/dope/core/handler.rb', line 14
def registrations
@registrations
end
|
Class Method Details
.register(route, path) ⇒ Object
16
17
18
|
# File 'lib/dope/core/handler.rb', line 16
def register(route, path)
registrations[route] = path
end
|
Instance Method Details
#content_type ⇒ Object
33
34
35
36
|
# File 'lib/dope/core/handler.rb', line 33
def content_type
m = mime_types
m.first.to_s if m
end
|
#extname ⇒ Object
25
26
27
|
# File 'lib/dope/core/handler.rb', line 25
def extname
File.extname(env['PATH_INFO'])
end
|
#mime_types ⇒ Object
29
30
31
|
# File 'lib/dope/core/handler.rb', line 29
def mime_types
MIME::Types.of(path)
end
|
#path ⇒ Object
21
22
23
|
# File 'lib/dope/core/handler.rb', line 21
def path
self.class.registrations[env['PATH_INFO']]
end
|
#to_rack_output ⇒ Object
38
39
40
41
|
# File 'lib/dope/core/handler.rb', line 38
def to_rack_output
raise NoSuchStaticFile, "no such file (#{path}) for #{env['PATH_INFO']}" unless path and File.file?(path)
[200, {'Content-Type' => content_type}, File.read(path)]
end
|