Class: Serve::FileTypeHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/serve/handlers/file_type_handler.rb

Overview

:nodoc:

Direct Known Subclasses

DynamicHandler, EmailHandler, RedirectHandler, SassHandler

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (FileTypeHandler) initialize(root_path, path)

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

+ (Object) extension(*extensions)



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

+ (Object) find(path)



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

+ (Object) handlers



3
4
5
# File 'lib/serve/handlers/file_type_handler.rb', line 3

def self.handlers
  @handlers ||= {}
end

Instance Method Details

- (Object) content_type



29
30
31
# File 'lib/serve/handlers/file_type_handler.rb', line 29

def content_type
  'text/html'
end

- (Object) parse(string)



33
34
35
# File 'lib/serve/handlers/file_type_handler.rb', line 33

def parse(string)
  string.dup
end

- (Object) process(request, response)



24
25
26
27
# File 'lib/serve/handlers/file_type_handler.rb', line 24

def process(request, response)
  response.headers['content-type'] = content_type
  response.body = parse(open(@script_filename){|io| io.read })
end