wand 0.3 → 0.4

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.
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wand (0.2.1)
4
+ wand (0.3)
5
5
  mime-types
6
+ safe_shell (~> 1.0.0)
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
@@ -11,6 +12,7 @@ GEM
11
12
  mocha (0.9.10)
12
13
  rake
13
14
  rake (0.8.7)
15
+ safe_shell (1.0.0)
14
16
  shoulda (2.11.3)
15
17
 
16
18
  PLATFORMS
@@ -19,5 +21,6 @@ PLATFORMS
19
21
  DEPENDENCIES
20
22
  mime-types
21
23
  mocha
24
+ safe_shell (~> 1.0.0)
22
25
  shoulda
23
26
  wand!
@@ -1,9 +1,10 @@
1
1
  require 'mime/types'
2
+ require 'safe_shell'
2
3
 
3
4
  module Wand
4
5
  def self.wave(path, options={})
5
6
  type = MIME::Types.type_for(options[:original_filename] || path)[0].to_s
6
- type = execute_file_cmd(path).split(';')[0].strip if type.nil? || type == ''
7
+ type = parse_type(execute_file_cmd(path)) if blank?(type)
7
8
  type = nil if type =~ /^cannot/i
8
9
  type
9
10
  end
@@ -16,7 +17,18 @@ module Wand
16
17
  @executable = path
17
18
  end
18
19
 
20
+ private
21
+ def self.parse_type(output)
22
+ type = output.split(';')[0]
23
+ type = type.strip unless type.nil?
24
+ type
25
+ end
26
+
19
27
  def self.execute_file_cmd(path)
20
- `#{executable} --mime --brief #{path}`
28
+ SafeShell.execute("#{executable}", "--mime", "--brief", path)
29
+ end
30
+
31
+ def self.blank?(str)
32
+ str.nil? || str == ''
21
33
  end
22
34
  end
@@ -1,3 +1,3 @@
1
1
  module Wand
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
@@ -3,7 +3,7 @@ require 'helper'
3
3
  class TestWand < Test::Unit::TestCase
4
4
  context "Wand" do
5
5
  setup do
6
- Wand.executable = `which file`.chomp
6
+ Wand.executable = nil
7
7
  end
8
8
 
9
9
  {
@@ -64,5 +64,14 @@ class TestWand < Test::Unit::TestCase
64
64
  Wand.expects(:execute_file_cmd).returns("cannot open file")
65
65
  assert_equal nil, Wand.wave('')
66
66
  end
67
+
68
+ should "properly handle bad stuff" do
69
+ assert_nothing_raised { Wand.wave(';blah') }
70
+ end
71
+
72
+ should "handle unexpected results frome execute file command" do
73
+ Wand.expects(:execute_file_cmd).returns('')
74
+ assert_equal nil, Wand.wave('')
75
+ end
67
76
  end
68
77
  end
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Mime-Type gem with fallback to unix file command}
14
14
 
15
15
  s.add_dependency 'mime-types'
16
+ s.add_dependency 'safe_shell', '~> 1.0.0'
16
17
 
17
18
  s.add_development_dependency 'shoulda'
18
19
  s.add_development_dependency 'mocha'
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wand
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- version: "0.3"
8
+ - 4
9
+ version: "0.4"
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Nunemaker
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-20 00:00:00 -05:00
17
+ date: 2011-01-22 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -32,9 +32,25 @@ dependencies:
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: shoulda
35
+ name: safe_shell
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: shoulda
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
38
54
  none: false
39
55
  requirements:
40
56
  - - ">="
@@ -44,11 +60,11 @@ dependencies:
44
60
  - 0
45
61
  version: "0"
46
62
  type: :development
47
- version_requirements: *id002
63
+ version_requirements: *id003
48
64
  - !ruby/object:Gem::Dependency
49
65
  name: mocha
50
66
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
67
+ requirement: &id004 !ruby/object:Gem::Requirement
52
68
  none: false
53
69
  requirements:
54
70
  - - ">="
@@ -58,7 +74,7 @@ dependencies:
58
74
  - 0
59
75
  version: "0"
60
76
  type: :development
61
- version_requirements: *id003
77
+ version_requirements: *id004
62
78
  description: Mime-Type gem with fallback to unix file command
63
79
  email:
64
80
  - nunemaker@gmail.com