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
21 def determine_mime_type(io)
22   analyzer = opts[:mime_type_analyzer]
23   analyzer = mime_type_analyzer(analyzer) if analyzer.is_a?(Symbol)
24   args     = [io, mime_type_analyzers].take(analyzer.arity.abs)
25 
26   mime_type = analyzer.call(*args)
27   io.rewind
28 
29   mime_type
30 end
mime_type_analyzer (name)

Returns callable mime type analyzer object.

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