Module: Shrine::Plugins::Transloadit

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

Defined Under Namespace

Modules: AttacherClassMethods, AttacherMethods, ClassMethods, FileMethods, InstanceMethods Classes: TransloaditFile

Class Method Summary collapse

Class Method Details

.configure(uploader, opts = {}) ⇒ Object

Accepts Transloadit credentials via ‘:auth_key` and `:auth_secret`.

If :cache storage wasn’t assigned, it will be assigned to a URL storage for direct uploads.

If promoting was not yet overriden, it is set to automatically trigger Transloadit processing defined in ‘Shrine#transloadit_process`.

Raises:

  • (Error)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/shrine/plugins/transloadit.rb', line 17

def self.configure(uploader, opts = {})
  uploader.opts[:transloadit_auth_key] = opts.fetch(:auth_key, uploader.opts[:transloadit_auth_key])
  uploader.opts[:transloadit_auth_secret] = opts.fetch(:auth_secret, uploader.opts[:transloadit_auth_secret])

  raise Error, "The :auth_key is required for transloadit plugin" if uploader.opts[:transloadit_auth_key].nil?
  raise Error, "The :auth_secret is required for transloadit plugin" if uploader.opts[:transloadit_auth_secret].nil?

  uploader.storages[:cache] ||= (
    require "shrine/storage/url"
    Shrine::Storage::Url.new
  )

  uploader.opts[:backgrounding_promote] ||= proc { transloadit_process }
end

.load_dependencies(uploader, opts = {}) ⇒ Object

It loads the backgrounding plugin, so that it can override promoting.



33
34
35
# File 'lib/shrine/plugins/transloadit.rb', line 33

def self.load_dependencies(uploader, opts = {})
  uploader.plugin :backgrounding
end