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

Returns callable mime type analyzer object.

[show source]
   # File lib/shrine/plugins/determine_mime_type.rb
48 def mime_type_analyzer(name)
49   MimeTypeAnalyzer.new(name)
50 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
41 def mime_type_analyzers
42   @mime_type_analyzers ||= MimeTypeAnalyzer::SUPPORTED_TOOLS.inject({}) do |hash, tool|
43     hash.merge!(tool => mime_type_analyzer(tool))
44   end
45 end