Class MIME::DiscreteMediaFactory
In: lib/mime/discrete_media_factory.rb
Parent: Object

Class object used only for initializing derived DiscreteMediaType objects.

Methods

create   new  

Included Modules

ContentTypes

Public Class methods

Creates a corresponding DiscreteMediaType subclass object for the given file based on file‘s filename extension. file can be a file path or File object.

content_type can be specified in order to override the auto detected content type. If the content_type cannot be detected, an UnknownContentError exception will be raised.

Creates and sets the singleton method path on the created object. The path method is utilized by other methods in the MIME library, therefore, eliminating redundant and explicit filename assignments.

Comparison Example

 entity1 = open('/tmp/file1.txt')
 entity2 = DiscreteMediaFactory.create('/tmp/file2.txt')

 mixed_msg = Multipart::Mixed.new
 mixed_msg.attach_entity(entity1.read, entity.path)
 mixed_msg.attach_entity(entity2) # no path needed

[Validate]