Module: Shrine::Plugins::DerivationEndpoint

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

Overview

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

Defined Under Namespace

Modules: ClassMethods, FileMethods

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

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



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 27

def self.configure(uploader, log_subscriber: LOG_SUBSCRIBER, **opts)
  uploader.opts[:derivation_endpoint] ||= { options: {}, derivations: {} }
  uploader.opts[:derivation_endpoint][:options].merge!(opts)

  unless uploader.opts[:derivation_endpoint][:options][:secret_key]
    fail Error, "must provide :secret_key option to derivation_endpoint plugin"
  end

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

.load_dependencies(uploader) ⇒ Object



22
23
24
25
# File 'lib/shrine/plugins/derivation_endpoint.rb', line 22

def self.load_dependencies(uploader, **)
  uploader.plugin :rack_response
  uploader.plugin :_urlsafe_serialization
end