Module: Shrine::Plugins::ConfigurableStorage

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

Overview

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

Defined Under Namespace

Modules: ClassMethods Classes: StorageNotConfigured

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



40
41
42
# File 'lib/shrine/plugins/configurable_storage.rb', line 40

def configuration
  @configuration
end

Class Method Details

.configure(uploader = nil, *_args) {|configuration| ... } ⇒ Object

Yields:



34
35
36
37
38
# 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) ⇒ Object



30
31
32
# File 'lib/shrine/plugins/configurable_storage.rb', line 30

def fetch(arg, &block)
  configuration.fetch(arg, &block)
end