module Shrine::Plugins::DynamicStorage

  1. lib/shrine/plugins/dynamic_storage.rb

The dynamic_storage plugin allows you to register a storage using a regex, and evaluate the storage class dynamically depending on the regex.

Example:

plugin :dynamic_storage

storage /store_(\w+)/ do |match|
  Shrine::Storages::S3.new(bucket: match[1])
end

The above example uses S3 storage where the bucket name depends on the storage name suffix. For example, :store_foo will use S3 storage which saves files to the bucket “foo”. The block is yielded an instance of MatchData.

This can be useful in combination with the default_storage plugin.

Methods

Public Class

  1. configure

Public Class methods

configure (uploader, options = {})
[show source]
# File lib/shrine/plugins/dynamic_storage.rb, line 23
def self.configure(uploader, options = {})
  uploader.opts[:dynamic_storages] ||= {}
end