Module: Shrine::Plugins::InferExtension

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

Overview

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

Defined Under Namespace

Modules: ClassMethods, InstanceMethods Classes: ExtensionInferrer

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

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


16
17
18
19
20
21
22
# File 'lib/shrine/plugins/infer_extension.rb', line 16

def self.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts)
  uploader.opts[:infer_extension] ||= { inferrer: :mini_mime }
  uploader.opts[:infer_extension].merge!(opts)

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