Skip to main content

Default Storage

The default_storage plugin allows you to change the default temporary and permanent storage a Shrine::Attacher object will use (the default is :cache and :store).

plugin :default_storage, cache: :other_cache, store: :other_store

If you want the storage to be dynamic based on Attacher data, you can use a block, and it will be evaluated in context of the Attacher instance:

plugin :default_storage, store: -> {
  if record.is_a?(Photo)
    :photo_store
  else
    :store
  end
}

You can also set default storage with Attacher#default_cache and Attacher#default_store:

# default temporary storage
Attacher.default_cache :other_cache
# or
Attacher.default_cache { :other_cache }

# default permanent storage
Attacher.default_store :other_store
# or
Attacher.default_store { :other_store }

The dynamic block is useful in combination with the dynamic_storage plugin.