Module: Shrine::Plugins::DetermineMimeType

Defined in:
lib/shrine/plugins/determine_mime_type.rb

Overview

Documentation can be found on shrinerb.com/docs/plugins/determine_mime_type

Defined Under Namespace

Modules: ClassMethods, InstanceMethods Classes: MimeTypeAnalyzer

Constant Summary collapse

LOG_SUBSCRIBER =
-> (event) do
  Shrine.logger.info "MIME Type (#{event.duration}ms) – #{{
    io:       event[:io].class,
    uploader: event[:uploader],
  }.inspect}"
end

Class Method Summary collapse

Class Method Details

.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts) ⇒ Object


14
15
16
17
18
19
20
# File 'lib/shrine/plugins/determine_mime_type.rb', line 14

def self.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts)
  uploader.opts[:determine_mime_type] ||= { analyzer: :file, analyzer_options: {} }
  uploader.opts[:determine_mime_type].merge!(opts)

  # instrumentation plugin integration
  uploader.subscribe(:mime_type, &log_subscriber) if uploader.respond_to?(:subscribe)
end