Class: MultiMime::Adapters::Mimemagic

Inherits:
MultiMime::Adapter show all
Defined in:
lib/multi_mime/adapters/mimemagic.rb

Overview

Use the Mimemagic library

Instance Method Summary collapse

Methods inherited from MultiMime::Adapter

type_for, type_for_extension, type_for_file, type_for_path

Instance Method Details

#type_for(mime_type, opts = {}) ⇒ Object



7
8
9
10
# File 'lib/multi_mime/adapters/mimemagic.rb', line 7

def type_for(mime_type, opts = {})
  type = ::MimeMagic::EXTENSIONS.key(mime_type) # Mimemagic actually doesnt allow you to simply verify that a mime type exists
  type ? mime_type : MultiMime::NullType.new
end

#type_for_extension(extension, opts = {}) ⇒ Object



12
13
14
# File 'lib/multi_mime/adapters/mimemagic.rb', line 12

def type_for_extension(extension, opts = {})
  ::MimeMagic.by_extension(extension) || MultiMime::NullType.new
end

#type_for_file(file, opts = {}) ⇒ Object



20
21
22
# File 'lib/multi_mime/adapters/mimemagic.rb', line 20

def type_for_file(file, opts = {})
  type_for_extension(File.extname(file))
end

#type_for_path(path, opts = {}) ⇒ Object



16
17
18
# File 'lib/multi_mime/adapters/mimemagic.rb', line 16

def type_for_path(path, opts = {})
  type_for_extension(File.extname(path))
end