Class: Marcel::MimeType
- Inherits:
-
Object
- Object
- Marcel::MimeType
- Defined in:
- lib/marcel/mime_type.rb
Constant Summary collapse
- BINARY =
"application/octet-stream"
Class Method Summary collapse
- .extend(type, extensions: [], parents: [], magic: nil) ⇒ Object
- .for(pathname_or_io = nil, name: nil, extension: nil, declared_type: nil) ⇒ Object
Class Method Details
.extend(type, extensions: [], parents: [], magic: nil) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/marcel/mime_type.rb', line 5 def extend(type, extensions: [], parents: [], magic: nil) existing = MimeMagic::TYPES[type] || [[], [], ""] extensions = (Array(extensions) + existing[0]).uniq parents = (Array(parents) + existing[1]).uniq comment = existing[2] MimeMagic.add(type, extensions: extensions, magic: magic, parents: parents, comment: comment) end |
.for(pathname_or_io = nil, name: nil, extension: nil, declared_type: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/marcel/mime_type.rb', line 15 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 |