Class: Marcel::MimeType

Inherits:
Object
  • Object
show all
Defined in:
lib/marcel/mime_type.rb

Constant Summary collapse

BINARY =
"application/octet-stream"

Class Method Summary collapse

Class Method Details

.extend(type, extensions: [], parents: [], magic: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/marcel/mime_type.rb', line 6

def extend(type, extensions: [], parents: [], magic: nil)
  existing = Marcel::TYPES[type] || [[], [], ""]

  extensions = (Array(extensions) + existing[0]).uniq
  parents = (Array(parents) + existing[1]).uniq
  comment = existing[2]

  Magic.add(type, extensions: extensions, magic: magic, parents: parents, comment: comment)
end

.for(pathname_or_io = nil, name: nil, extension: nil, declared_type: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/marcel/mime_type.rb', line 16

def for(pathname_or_io = nil, name: nil, extension: nil, declared_type: nil)
  type_from_data = for_data(pathname_or_io)
  fallback_type = for_declared_type(declared_type) || for_name(name) || for_extension(extension) || BINARY

  if type_from_data
    most_specific_type type_from_data, fallback_type
  else
    fallback_type
  end
end