Class: Kiss::StaticFile
Instance Method Summary collapse
- #each ⇒ Object
- #finish ⇒ Object
-
#initialize(path, options = {}) ⇒ StaticFile
constructor
A new instance of StaticFile.
Constructor Details
#initialize(path, options = {}) ⇒ StaticFile
Returns a new instance of StaticFile.
3 4 5 6 |
# File 'lib/kiss/static_file.rb', line 3 def initialize(path, = {}) @_path = path @_options = end |
Instance Method Details
#each ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/kiss/static_file.rb', line 30 def each File.open(@_path, "rb") { |file| while part = file.read(8192) yield part end } end |
#finish ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kiss/static_file.rb', line 8 def finish ext = File.extname(@_path)[1..-1] headers = { "Last-Modified" => File.mtime(@_path).rfc822, "Content-Type" => @_options[:type] || Kiss.mime_type(ext) || "text/plain", "Content-Length" => File.size(@_path).to_s } if @_options[:filename] headers['Content-Disposition'] = "#{@_options[:disposition] || 'inline'}; filename=#{@_options[:filename]}" elsif @_options[:disposition] headers['Content-Disposition'] = @_options[:disposition] end if File.file?(@_path) && File.readable?(@_path) [200, headers, self] else raise "file not found: #{@_path}" end end |