file_wrapper 0.3.0

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Wes Oldenbeuving
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ FileWrapper
2
+ ===========
3
+
4
+ FileWrapper is a Rails plugin which wraps the command line utility 'file' to detect the mime-type of a file.
5
+
6
+ Installation
7
+ =======
8
+
9
+ From the Rails project root, execute:
10
+ script/plugin install git://github.com/Narnach/file_wrapper.git
11
+
12
+ Example
13
+ =======
14
+
15
+ Detect the mime-type of a file.
16
+ FileWrapper.get_mime('Rakefile') #=> 'text/plain'
17
+
18
+
19
+ Copyright (c) 2008 Wes Oldenbeuving, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require "rake/gempackagetask"
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the file_wrapper plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the file_wrapper plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'FileWrapper'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ # Parse gemspec using the github safety level.
27
+ data = File.read('file_wrapper.gemspec')
28
+ spec = nil
29
+ Thread.new { spec = eval("$SAFE = 3\n%s" % data)}.join
30
+
31
+ # Create the gem tasks
32
+ Rake::GemPackageTask.new(spec) do |package|
33
+ package.gem_spec = spec
34
+ end
35
+ rescue Exception => e
36
+ printf "WARNING: Error caught (%s): %s\n", e.class.name, e.message
37
+ end
38
+
39
+ desc 'Package and install the gem for the current version'
40
+ task :install => :gem do
41
+ system "sudo gem install -l pkg/file_wrapper-%s.gem" % spec.version
42
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ # Project
3
+ s.name = 'file_wrapper'
4
+ s.summary = "FileWrapper wraps the command line utility 'file' to detect the mime-type of a file."
5
+ s.description = "FileWrapper is a RubyGem which wraps the command line utility 'file' to detect the mime-type of a file."
6
+ s.version = '0.3.0'
7
+ s.date = '2008-08-05'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Wes Oldenbeuving"]
10
+ s.email = "narnach@gmail.com"
11
+ s.homepage = "http://www.github.com/Narnach/file_wrapper"
12
+
13
+ # Files
14
+ s.require_path = "lib"
15
+ s.files = ['file_wrapper.gemspec', 'MIT-LICENSE', 'README.rdoc', 'Rakefile', 'init.rb', 'lib/file_wrapper.rb', 'test/file_wrapper_test.rb']
16
+ s.test_files = ['test/file_wrapper_test.rb']
17
+ s.autorequire = "init.rb"
18
+
19
+ # rdoc
20
+ s.has_rdoc = true
21
+ s.extra_rdoc_files = %w[ README.rdoc MIT-LICENSE]
22
+ s.rdoc_options << '--inline-source' << '--line-numbers' << '--main' << 'README.rdoc'
23
+
24
+ # Requirements
25
+ s.required_ruby_version = ">= 1.8.0"
26
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Include hook code here
2
+ require 'file_wrapper'
@@ -0,0 +1,16 @@
1
+ # FileWrapper wraps the 'file' command line utility.
2
+ class FileWrapper
3
+ class << self
4
+ # Extract the mime type from a file.
5
+ def get_mime(filename)
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
8
+ matches = file_output.match(/.+?:\s+([\/\d\w-]+\/[\/\d\w-]+)/)
9
+ if matches
10
+ return matches[1]
11
+ else
12
+ return nil
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require 'file_wrapper'
3
+
4
+ class FileWrapperTest < Test::Unit::TestCase
5
+ def test_rakefile_is_text
6
+ assert_equal 'text/plain', FileWrapper.get_mime('Rakefile')
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Wes Oldenbeuving
8
+ autorequire: init.rb
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-05 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: FileWrapper is a RubyGem which wraps the command line utility 'file' to detect the mime-type of a file.
17
+ email: narnach@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - MIT-LICENSE
25
+ files:
26
+ - file_wrapper.gemspec
27
+ - MIT-LICENSE
28
+ - README.rdoc
29
+ - Rakefile
30
+ - init.rb
31
+ - lib/file_wrapper.rb
32
+ - test/file_wrapper_test.rb
33
+ has_rdoc: true
34
+ homepage: http://www.github.com/Narnach/file_wrapper
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --inline-source
40
+ - --line-numbers
41
+ - --main
42
+ - README.rdoc
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.8.0
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.4
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: FileWrapper wraps the command line utility 'file' to detect the mime-type of a file.
64
+ test_files:
65
+ - test/file_wrapper_test.rb