Narnach-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,21 @@
1
+ = FileWrapper
2
+
3
+ FileWrapper is a Rails plugin and RubyGem which wraps the command line utility 'file' to detect the mime-type of a file.
4
+
5
+ == Installation as Rails plugin
6
+
7
+ From the Rails project root, execute:
8
+ script/plugin install git://github.com/Narnach/file_wrapper.git
9
+
10
+ == Installation as gem
11
+
12
+ Install the gem by executing:
13
+ sudo gem install Narnach-file_wrapper --remote --source http://gems.github.com
14
+
15
+ == Example
16
+
17
+ Detect the mime-type of a file.
18
+ FileWrapper.get_mime('Rakefile') #=> 'text/plain'
19
+
20
+
21
+ 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,25 @@
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 and Rails plugin 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
+
18
+ # rdoc
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = %w[ README.rdoc MIT-LICENSE]
21
+ s.rdoc_options << '--inline-source' << '--line-numbers' << '--main' << 'README.rdoc'
22
+
23
+ # Requirements
24
+ s.required_ruby_version = ">= 1.8.0"
25
+ 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,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Narnach-file_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Wes Oldenbeuving
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-05 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: FileWrapper is a RubyGem and Rails plugin 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
+ post_install_message:
36
+ rdoc_options:
37
+ - --inline-source
38
+ - --line-numbers
39
+ - --main
40
+ - README.rdoc
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.0
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: FileWrapper wraps the command line utility 'file' to detect the mime-type of a file.
62
+ test_files:
63
+ - test/file_wrapper_test.rb