Class: Mojito::Rendering::File::FileResponse
- Inherits:
-
Object
- Object
- Mojito::Rendering::File::FileResponse
- Defined in:
- lib/mojito/rendering/file.rb
Instance Method Summary collapse
- #compute_headers ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(pathname) ⇒ FileResponse
constructor
A new instance of FileResponse.
- #mime_type ⇒ Object
- #size ⇒ Object
- #to_path ⇒ Object
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_headers ⇒ Object
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_type ⇒ Object
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 |
#size ⇒ Object
42 43 44 |
# File 'lib/mojito/rendering/file.rb', line 42 def size @pathname.size end |
#to_path ⇒ Object
46 47 48 |
# File 'lib/mojito/rendering/file.rb', line 46 def to_path @pathname.to_s end |