module Shrine::Plugins::DetermineMimeType::ClassMethods

  1. lib/shrine/plugins/determine_mime_type.rb

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 96
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_analyzer(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_analyzer (name)

Returns callable mime type analyzer object.

[show source]
# File lib/shrine/plugins/determine_mime_type.rb, line 121
def mime_type_analyzer(name)
  MimeTypeAnalyzer.new(name).method(:call)
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 114
def mime_type_analyzers
  @mime_type_analyzers ||= MimeTypeAnalyzer::SUPPORTED_TOOLS.inject({}) do |hash, tool|
    hash.merge!(tool => mime_type_analyzer(tool))
  end
end