module Shrine::Plugins::KeepFiles

  1. lib/shrine/plugins/keep_files.rb

The keep_files plugin gives you the ability to prevent files from being deleted. This functionality is useful when implementing soft deletes, or when implementing some kind of event store where you need to track history.

The plugin accepts the following options:

:destroyed

If set to true, destroying the record won't delete the associated attachment.

:replaced

If set to true, uploading a new attachment won't delete the old one.

For example, the following will keep destroyed and replaced files:

plugin :keep_files, destroyed: true, replaced: true

Methods

Public Class

  1. configure

Public Class methods

configure (uploader, opts = {})
[show source]
# File lib/shrine/plugins/keep_files.rb, line 23
def self.configure(uploader, opts = {})
  keep_files = (uploader.opts[:keep_files] ||= [])
  opts[:destroyed] ? keep_files << :destroyed : keep_files.delete(:destroyed) if opts.key?(:destroyed)
  opts[:replaced] ? keep_files << :replaced : keep_files.delete(:replaced) if opts.key?(:replaced)
end