sinatra-xsendfile 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ begin
8
8
  require 'jeweler'
9
9
  Jeweler::Tasks.new do |gemspec|
10
10
  gemspec.name = "sinatra-xsendfile"
11
- gemspec.version = "0.1.2"
11
+ gemspec.version = "0.2.0"
12
12
  gemspec.summary = gemspec.description = "X-SendFile helpers for Sinatra"
13
13
  gemspec.email = "vasily@polovnyov.ru"
14
14
  gemspec.homepage = "http://github.com/vast/sinatra-xsendfile"
@@ -1,12 +1,9 @@
1
1
  require 'sinatra/base'
2
2
  module Sinatra
3
-
4
3
  module XSendFile
5
4
  def x_send_file(path, opts = {})
6
- stat = File.stat(path)
7
-
8
- content_type media_type(opts[:type]) ||
9
- media_type(File.extname(path)) ||
5
+ content_type _mime_type(opts[:type]) ||
6
+ _mime_type(File.extname(path)) ||
10
7
  response['Content-Type'] ||
11
8
  'application/octet-stream'
12
9
 
@@ -27,6 +24,14 @@ module Sinatra
27
24
  not_found
28
25
  end
29
26
 
27
+ def _mime_type(type)
28
+ if respond_to?(:mime_type)
29
+ mime_type(type)
30
+ else
31
+ media_type(type)
32
+ end
33
+ end
34
+
30
35
  def self.replace_send_file!
31
36
  Sinatra::Helpers.send(:alias_method, :old_send_file, :send_file)
32
37
  Sinatra::Helpers.module_eval("def send_file(path, opts={}); x_send_file(path, opts); end;")
@@ -34,4 +39,4 @@ module Sinatra
34
39
  end
35
40
 
36
41
  helpers XSendFile
37
- end
42
+ end
@@ -31,8 +31,4 @@ class SinatraXSendFileTest < Test::Unit::TestCase
31
31
  assert_not_nil last_response.headers['x-test-send-file']
32
32
  end
33
33
 
34
- def test_sendfile_overriding
35
- get '/sendfile'
36
- assert_not_nil last_response.headers['x-test-send-file']
37
- end
38
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-xsendfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Polovnyov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-18 00:00:00 +03:00
12
+ date: 2010-03-12 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency