wand 0.1 → 0.2
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/Rakefile +1 -0
- data/lib/wand.rb +7 -2
- data/test/helper.rb +1 -0
- data/test/test_wand.rb +11 -1
- data/wand.gemspec +74 -0
- metadata +13 -2
data/Rakefile
CHANGED
data/lib/wand.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'mime/types'
|
2
|
+
require 'shellwords'
|
2
3
|
|
3
4
|
module Wand
|
4
|
-
Version = '0.
|
5
|
+
Version = '0.2'
|
5
6
|
|
6
7
|
def self.wave(path)
|
7
8
|
type = MIME::Types.type_for(path)[0].to_s
|
8
|
-
type =
|
9
|
+
type = execute_file_cmd(path).split(';')[0].strip if type.nil? || type == ''
|
9
10
|
type = nil if type =~ /cannot\sopen/
|
10
11
|
type
|
11
12
|
end
|
@@ -18,4 +19,8 @@ module Wand
|
|
18
19
|
def self.executable=(path)
|
19
20
|
@executable = path
|
20
21
|
end
|
22
|
+
|
23
|
+
def self.execute_file_cmd(path)
|
24
|
+
`#{executable} --mime --brief #{path.shellescape}`
|
25
|
+
end
|
21
26
|
end
|
data/test/helper.rb
CHANGED
data/test/test_wand.rb
CHANGED
@@ -5,7 +5,7 @@ class TestWand < Test::Unit::TestCase
|
|
5
5
|
setup do
|
6
6
|
Wand.executable = `which file`.chomp
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
{
|
10
10
|
'AVGARDD.svg' => 'image/svg+xml',
|
11
11
|
'compressed.zip' => 'application/zip',
|
@@ -44,5 +44,15 @@ class TestWand < Test::Unit::TestCase
|
|
44
44
|
Wand.executable = '/usr/local/bin/file'
|
45
45
|
assert_equal '/usr/local/bin/file', Wand.executable
|
46
46
|
end
|
47
|
+
|
48
|
+
should "strip newlines and such" do
|
49
|
+
Wand.expects(:execute_file_cmd).returns("image/jpeg\n")
|
50
|
+
assert_equal "image/jpeg", Wand.wave(FilePath.join(name).expand_path.to_s)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "escape path" do
|
54
|
+
output = Wand.execute_file_cmd(FilePath.join(name).expand_path.to_s + ' && echo $USER')
|
55
|
+
assert_match /cannot\sopen/, output
|
56
|
+
end
|
47
57
|
end
|
48
58
|
end
|
data/wand.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{wand}
|
8
|
+
s.version = "0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["John Nunemaker"]
|
12
|
+
s.date = %q{2010-03-08}
|
13
|
+
s.description = %q{Mime-Type gem with fallback to unix file command}
|
14
|
+
s.email = %q{nunemaker@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"lib/wand.rb",
|
26
|
+
"test/files/AVGARDD.eot",
|
27
|
+
"test/files/AVGARDD.svg",
|
28
|
+
"test/files/AVGARDD.ttf",
|
29
|
+
"test/files/AVGARDD.woff",
|
30
|
+
"test/files/compressed.zip",
|
31
|
+
"test/files/example.m4r",
|
32
|
+
"test/files/favicon.ico",
|
33
|
+
"test/files/index.html",
|
34
|
+
"test/files/jquery.js",
|
35
|
+
"test/files/ol_tiny.jpg",
|
36
|
+
"test/files/ol_tiny.png",
|
37
|
+
"test/files/styles.css",
|
38
|
+
"test/helper.rb",
|
39
|
+
"test/test_wand.rb",
|
40
|
+
"wand.gemspec"
|
41
|
+
]
|
42
|
+
s.homepage = %q{http://github.com/jnunemaker/wand}
|
43
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = %q{1.3.5}
|
46
|
+
s.summary = %q{Mime-Type gem with fallback to unix file command}
|
47
|
+
s.test_files = [
|
48
|
+
"test/helper.rb",
|
49
|
+
"test/test_wand.rb"
|
50
|
+
]
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_runtime_dependency(%q<mime-types>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<mime-types>, [">= 0"])
|
63
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
65
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
66
|
+
end
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<mime-types>, [">= 0"])
|
69
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
70
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
71
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-08 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,6 +42,16 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: "0"
|
44
44
|
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: mocha
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
45
55
|
description: Mime-Type gem with fallback to unix file command
|
46
56
|
email: nunemaker@gmail.com
|
47
57
|
executables: []
|
@@ -72,6 +82,7 @@ files:
|
|
72
82
|
- test/files/styles.css
|
73
83
|
- test/helper.rb
|
74
84
|
- test/test_wand.rb
|
85
|
+
- wand.gemspec
|
75
86
|
has_rdoc: true
|
76
87
|
homepage: http://github.com/jnunemaker/wand
|
77
88
|
licenses: []
|