Module: Shrine::Plugins::Derivatives

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

Overview

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

Defined Under Namespace

Modules: AttacherClassMethods, AttacherMethods, AttachmentMethods, ClassMethods, FileMethods, VersionsCompatibility

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

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


21
22
23
24
25
26
27
# File 'lib/shrine/plugins/derivatives.rb', line 21

def self.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts)
  uploader.opts[:derivatives] ||= { processors: {}, processor_settings: {}, storage: proc { store_key } }
  uploader.opts[:derivatives].merge!(opts)

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

.load_dependencies(uploader, versions_compatibility: false) ⇒ Object


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

def self.load_dependencies(uploader, versions_compatibility: false, **)
  uploader.plugin :default_url

  AttacherMethods.prepend(VersionsCompatibility) if versions_compatibility
end