Class: SimpleImagesDownloader::Validatable::MimeTypeValidator

Inherits:
Validator
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/simple_images_downloader/validatable/mime_type_validator.rb

Overview

MimeTypeValidator class Responsible for validating mime type of file

Examples:

SimpleImagesDownloader::MimeTypeValidator.new.validate({ path: './image.jpg', io: StringIO.new })

Instance Method Summary collapse

Instance Method Details

#validate(options) ⇒ Object

Validates mime type of file. The mime types are taken from file Configuration

Parameters:

  • options (Hash)

    hash with path to file and io object. Example: { path: ‘./image.jpg’, io: StringIO }

Raises:

See Also:



21
22
23
24
25
26
27
28
29
30
# File 'lib/simple_images_downloader/validatable/mime_type_validator.rb', line 21

def validate(options)
  path = options[:path]
  io   = options[:io]

  mime_type = mime_type_of(io)

  return if SimpleImagesDownloader::Configuration.valid_mime_types.include?(mime_type)

  raise Errors::BadMimeType.new(path, mime_type)
end