module Shrine::Plugins::DetermineMimeType::ClassMethods

  1. lib/shrine/plugins/determine_mime_type.rb

Methods

Public Instance

  1. determine_mime_type
  2. mime_type_analyzers

Public Instance methods

determine_mime_type (io)

Determines the MIME type of the IO object by calling the specified analyzer.

[show source]
# File lib/shrine/plugins/determine_mime_type.rb, line 82
def determine_mime_type(io)
  if opts[:mime_type_analyzer] == :default
    mime_type = io.content_type if io.respond_to?(:content_type)
  else
    analyzer = opts[:mime_type_analyzer]
    analyzer = mime_type_analyzers[analyzer] if analyzer.is_a?(Symbol)
    args     = [io, mime_type_analyzers].take(analyzer.arity.abs)

    mime_type = analyzer.call(*args)
    io.rewind
  end

  mime_type
end
mime_type_analyzers ()

Returns a hash of built-in MIME type analyzers, where keys are analyzer names and values are #call-able objects which accepts the IO object.

[show source]
# File lib/shrine/plugins/determine_mime_type.rb, line 100
def mime_type_analyzers
  @mime_type_analyzers ||= MimeTypeAnalyzer::SUPPORTED_TOOLS.inject({}) do |hash, tool|
    hash.merge!(tool => MimeTypeAnalyzer.new(tool).method(:call))
  end
end