lib/wand.rb in wand-0.3 vs lib/wand.rb in wand-0.4
- old
+ new
@@ -1,11 +1,12 @@
require 'mime/types'
+require 'safe_shell'
module Wand
def self.wave(path, options={})
type = MIME::Types.type_for(options[:original_filename] || path)[0].to_s
- type = execute_file_cmd(path).split(';')[0].strip if type.nil? || type == ''
+ type = parse_type(execute_file_cmd(path)) if blank?(type)
type = nil if type =~ /^cannot/i
type
end
def self.executable
@@ -14,9 +15,20 @@
def self.executable=(path)
@executable = path
end
+private
+ def self.parse_type(output)
+ type = output.split(';')[0]
+ type = type.strip unless type.nil?
+ type
+ end
+
def self.execute_file_cmd(path)
- `#{executable} --mime --brief #{path}`
+ SafeShell.execute("#{executable}", "--mime", "--brief", path)
+ end
+
+ def self.blank?(str)
+ str.nil? || str == ''
end
end