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.

NOTE: This implementation can be made a lot simpler once this PR is in a shrine release: github.com/shrinerb/shrine/pull/319 github.com/shrinerb/shrine/commit/88c23d54814568b04987680f00b6b36f421c8d81

Defined Under Namespace

Modules: AttacherMethods

Class Method Summary collapse

Class Method Details

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



31
32
33
# File 'lib/shrine/plugins/kithe_multi_cache.rb', line 31

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