module Shrine::Plugins::DetermineMimeType::ClassMethods

  1. lib/shrine/plugins/determine_mime_type.rb

Public Instance Aliases

mime_type -> determine_mime_type

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

Returns callable mime type analyzer object.

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