5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/see_as_vee/helpers.rb', line 5
def file_with_type whatever
file = case whatever
when IO then whatever
when String
File.exist?(whatever) ? File.new(whatever) : Privates.tempfile(whatever)
else
raise SeeAsVee::Exceptions::BadInputError.new(whatever)
end
[
file,
(Privates.handler_name(FileMagic.new.file(file.path)) if Kernel.const_defined?('FileMagic')) ||
Privates.handler_by_ext(file.path[/(?<=\.).*\z/])
].tap do |_, handle|
raise SeeAsVee::Exceptions::FileFormatError.new(file.path) if handle.nil?
end
end
|