Class: Mojito::Rendering::File::FileResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/mojito/rendering/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(pathname) ⇒ FileResponse

Returns a new instance of FileResponse.



24
25
26
# File 'lib/mojito/rendering/file.rb', line 24

def initialize(pathname)
	@pathname = pathname
end

Instance Method Details

#compute_headersObject



34
35
36
# File 'lib/mojito/rendering/file.rb', line 34

def compute_headers
	{ 'Content-Type' => mime_type.to_s, 'Content-Length' => size.to_s, 'Last-Modified' => @pathname.mtime.rfc2822 }
end

#each(&block) ⇒ Object



28
29
30
31
32
# File 'lib/mojito/rendering/file.rb', line 28

def each(&block)
	@pathname.open do |f|
		yield f.read
	end
end

#mime_typeObject



38
39
40
# File 'lib/mojito/rendering/file.rb', line 38

def mime_type
	MIME::Types.type_for(@pathname.to_s).first || MIME::Types['application/octet-stream'].first
end

#sizeObject



42
43
44
# File 'lib/mojito/rendering/file.rb', line 42

def size
	@pathname.size
end

#to_pathObject



46
47
48
# File 'lib/mojito/rendering/file.rb', line 46

def to_path
	@pathname.to_s
end