Module: Shrine::Plugins::KitheMultiCache

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

Overview

Allows an uploader to have more than one ‘cache’ – although the main one registered as normal will ordinarily be used, you can manually assign UploadedFiles (or hashes) specifying other caches, and they will be accepted, and promoted.

Invented for use with shrine-url.

Shrine.storages = {
  cache: ...,
  store: ...,
  remote_url: Shrine::Storage::Url.new
 }

class SomeUploader < Shrine
  plugin :kithe_multi_cache, additional_cache: [:remote_url, :something_else]
  ...
end

Now in your model, you can

my_model.attached_file = { "id" => "http://example.com", "storage" => "remote_url"}

And the data can be saved, and the remote url (shrine-url) file will be promoted as usual, even though it’s not registered as the cache storage.

Defined Under Namespace

Modules: AttacherMethods

Class Method Summary collapse

Class Method Details

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



28
29
30
# File 'lib/shrine/plugins/kithe_multi_cache.rb', line 28

def self.configure(uploader, options = {})
  uploader.opts[:kithe_multi_cache_keys]  = Array(options[:additional_cache]).collect(&:to_sym)
end