Sha256: d7f5526c576e656b37a78d1f18c916509c592dc0340f89677eeacafc60859220
Contents?: true
Size: 1.57 KB
Versions: 28
Compression:
Stored size: 1.57 KB
Contents
class Shrine module Plugins # 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. # module KitheMultiCache def self.configure(uploader, options = {}) uploader.opts[:kithe_multi_cache_keys] = Array(options[:additional_cache]).collect(&:to_sym) end # override #cache to lazily extend with our custom module. Kinda hacky, # but couldn't think of any other way to only extend the "cache" uploader, # and not the "store" uploader. module AttacherMethods def cached?(file = self.file) super || (file && shrine_class.opts[:kithe_multi_cache_keys].include?(file.storage_key.to_sym)) end end end register_plugin(:kithe_multi_cache, KitheMultiCache) end end
Version data entries
28 entries across 28 versions & 1 rubygems