Permalink
Browse files

Allow overriding the path with :orignal_filename

When passing a multipart uploaded file to wand it is generally
a temp file with no extension leaving MIME with no way to detect
the type.
  • Loading branch information...
1 parent 426c210 commit 467ad9b57ecad1bf5c5da91c60f39cfe95cdc163 @raykrueger raykrueger committed with Nov 15, 2010
Showing with 7 additions and 3 deletions.
  1. +3 −3 lib/wand.rb
  2. +4 −0 test/test_wand.rb
View
@@ -3,8 +3,8 @@
module Wand
Version = '0.2.1'
- def self.wave(path)
- type = MIME::Types.type_for(path)[0].to_s
+ def self.wave(path, options={})
+ type = MIME::Types.type_for(options[:original_filename] || path)[0].to_s
type = execute_file_cmd(path).split(';')[0].strip if type.nil? || type == ''
type = nil if type =~ /cannot\sopen/
type
@@ -21,4 +21,4 @@ def self.executable=(path)
def self.execute_file_cmd(path)
`#{executable} --mime --brief #{path}`
end
-end
+end
View
@@ -32,6 +32,10 @@ class TestWand < Test::Unit::TestCase
end
end
+ should "return value from mime type when original_filename provided" do
+ assert_equal 'audio/mpeg', Wand.wave('some_temp_file', :original_filename => 'test.mp3')
+ end
+
should "return nil when mime type and file fail" do
assert_nil Wand.wave('AVGARDD.eot')
end

0 comments on commit 467ad9b

Please sign in to comment.