class Shrine::Plugins::DetermineMimeType::MimeTypeAnalyzer

  1. lib/shrine/plugins/determine_mime_type.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. call

Constants

MAGIC_NUMBER = 256 * 1024  
SUPPORTED_TOOLS = [:file, :filemagic, :mimemagic, :mime_types, :mini_mime]  

Public Class methods

new (tool)
[show source]
# File lib/shrine/plugins/determine_mime_type.rb, line 131
def initialize(tool)
  raise ArgumentError, "unsupported mime type analysis tool: #{tool}" unless SUPPORTED_TOOLS.include?(tool)

  @tool = tool
end

Public Instance methods

call (io)
[show source]
# File lib/shrine/plugins/determine_mime_type.rb, line 137
def call(io)
  return nil if io.eof? # empty file doesn't have a MIME type

  mime_type = send(:"extract_with_#{@tool}", io)
  io.rewind

  mime_type
end