module Shrine::Plugins::ConfigurableStorage

The {ConfigurableStorage} plugin allows you to register a storage using a config key, and evaluate the storage class dynamically depending on the key. The configuration is global and can be shared across uploaders.

Example: Setup storage for images

# in your uploader

plugin :configurable_storage
configurable_storage_name :images

# in an initializer, or somewhere else (because this is lazy)

Shrine::Plugins::ConfigurableStorage.configure do |config|
  config[:images] = {
    cache: Shrine::Storage::Memory.new,
    store: Shrine::Storage::FileSystem.new('uploads', prefix: 'img')
  }
end

Attributes

configuration[RW]

Public Class Methods

configure(uploader = nil, *_args) { |configuration| ... } click to toggle source
# File lib/shrine/plugins/configurable_storage.rb, line 34
def configure(uploader = nil, *_args)
  return uploader.setup unless block_given?

  yield configuration
end
fetch(arg, &block) click to toggle source
# File lib/shrine/plugins/configurable_storage.rb, line 30
def fetch(arg, &block)
  configuration.fetch(arg, &block)
end