Class: Dope::StaticFileHandler

Inherits:
Derailleur::RackHandler
  • Object
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

.registrationsObject (readonly)

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_typeObject



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

#extnameObject



25
26
27
# File 'lib/dope/core/handler.rb', line 25

def extname
  File.extname(env['PATH_INFO'])
end

#mime_typesObject



29
30
31
# File 'lib/dope/core/handler.rb', line 29

def mime_types
  MIME::Types.of(path)
end

#pathObject



21
22
23
# File 'lib/dope/core/handler.rb', line 21

def path
  self.class.registrations[env['PATH_INFO']]
end

#to_rack_outputObject

Raises:



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