Keep_files but only for a specific Uploader

Hi,
It is not entirely clear to me if I could use a plugin only for a specific uploader. Like I want to use the keep_files pluging Keep Files · Shrine but only for one of the classes in our platform.

Do you think this is possible? Is there a specific part of the documentation that I am overlooking?

Each Shrine plugin can be applied either globally or for a specific uploader. In your case, you can load keep_files inside your uploader:

class MyUploader < Shrine
  plugin :keep_files
end
1 Like

Thanks. That’s really helpful. Is there a place in the docs that I’ve missed?

@janko
I am lost with the following spec as I was preparing a spec for keep_files.

I don’t use keep_files and i would expect that the file is deleted from the store. But UploadedFile.exists? returns true

 it "keeps them in the store on delete" do
      material.source = File.open("spec/fixtures/files/material_src.zip", "rb")
      material.save
      undeleted_source = material.source
      material.update(source_data: nil)
      material.reload
      expect(material.source).to eq nil
      # There is no keep_files. Why does this source exists?
      # This here fails
      expect(undeleted_source.exists?).to eq false
    end

  1) Material source files keeps them in the store on delete
     Failure/Error: expect(undeleted_source.exists?).to eq false
     
       expected: false
            got: true
     

Why would exists? return true? Is this spec correctly using shrine api?

Is there a place in the docs that I’ve missed?

If you’re referring to the plugin system inheritance, there is a section in the getting started guide explaining applying plugins globally and per uploader. If you think it could be clearer, I’m always open to PRs.

I don’t use keep_files and i would expect that the file is deleted from the store. But UploadedFile.exists? returns true

You must clear the attachment by assigning to the attachment attribute, not the column directly:

material.update(source: nil) # not :source_data

Shrine doesn’t detect changes that happen at the column level, everything should go through Shrine attributes.

Thanks. There is it this section. I must have overlooked it.

Thanks. I will try to update the source itself.