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 102
def determine_mime_type(io)
  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

  mime_type
end
mime_type_analyzer (name)

Returns callable mime type analyzer object.

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