file_wrapper 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +22 -0
- data/file_wrapper.gemspec +1 -1
- data/lib/file_wrapper.rb +1 -1
- data/test/file_wrapper_test.rb +12 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -17,5 +17,27 @@ Install the gem by executing:
|
|
17
17
|
Detect the mime-type of a file.
|
18
18
|
FileWrapper.get_mime('Rakefile') #=> 'text/plain'
|
19
19
|
|
20
|
+
== Changelog
|
21
|
+
|
22
|
+
== Version 0.4.1
|
23
|
+
* FileWrapper can now handle filenames with spaces as it wraps it in double quotes.
|
24
|
+
|
25
|
+
== Version 0.4.0
|
26
|
+
* Removed unneeded autorequire from gemspec
|
27
|
+
* Updated readme with gem install instructions
|
28
|
+
* Updated gemspec
|
29
|
+
* Another small documentation update
|
30
|
+
* Updated readme
|
31
|
+
* Removed unused files
|
32
|
+
|
33
|
+
== Version 0.3.0
|
34
|
+
* Added gemspec: this is no longer a plugin but a stand-alone gem which should still work as a rails plugin.
|
35
|
+
* Renamed readme
|
36
|
+
* Ignored gem output directory
|
37
|
+
* Updated readme with installation instructions.
|
38
|
+
* Added plugin to git.
|
39
|
+
|
40
|
+
== Contributors
|
41
|
+
* Filip 'FiXato' Slagter
|
20
42
|
|
21
43
|
Copyright (c) 2008 Wes Oldenbeuving, released under the MIT license
|
data/file_wrapper.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.name = 'file_wrapper'
|
4
4
|
s.summary = "FileWrapper wraps the command line utility 'file' to detect the mime-type of a file."
|
5
5
|
s.description = "FileWrapper is a RubyGem and Rails plugin which wraps the command line utility 'file' to detect the mime-type of a file."
|
6
|
-
s.version = '0.4.
|
6
|
+
s.version = '0.4.1'
|
7
7
|
s.date = '2009-01-14'
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Wes Oldenbeuving"]
|
data/lib/file_wrapper.rb
CHANGED
@@ -4,7 +4,7 @@ class FileWrapper
|
|
4
4
|
# Extract the mime type from a file.
|
5
5
|
def get_mime(filename)
|
6
6
|
raise ArgumentError, "Invalid file" unless File.exist? filename and File.file? filename and File.readable? filename
|
7
|
-
file_output = `file --mime #{filename} 2>&1`.strip
|
7
|
+
file_output = `file --mime "#{filename}" 2>&1`.strip
|
8
8
|
matches = file_output.match(/.+?:\s+([\/\d\w-]+\/[\/\d\w-]+)/)
|
9
9
|
if matches
|
10
10
|
return matches[1]
|
data/test/file_wrapper_test.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
|
1
3
|
require 'test/unit'
|
2
4
|
require 'file_wrapper'
|
5
|
+
require 'tempfile'
|
3
6
|
|
4
7
|
class FileWrapperTest < Test::Unit::TestCase
|
5
8
|
def test_rakefile_is_text
|
6
9
|
assert_equal 'text/plain', FileWrapper.get_mime('Rakefile')
|
7
10
|
end
|
11
|
+
|
12
|
+
def test_filenames_with_spaces
|
13
|
+
Tempfile.open('text file with spaces.txt') do |f|
|
14
|
+
File.open(f.path,'w') do |fp|
|
15
|
+
fp.puts 'test'
|
16
|
+
end
|
17
|
+
assert_equal 'text/plain', FileWrapper.get_mime(f.path)
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|