Shrine

How do I create a slimmed-down "read-only" attacher for an API?

I have an existing application which works well, and is set up in the usual manner with all the validation and metadata extraction bits included. Here’s what that attacher looks like:

class BannerUploader < Shrine
  plugin :remove_attachment
  plugin :determine_mime_type
  plugin :validation_helpers
  plugin :store_dimensions
  
  Attacher.validate do
    if validate_mime_type %w[image/jpeg image/png image/webp], message: "must be JPEG, PNG or WEBP"
      validate_extension_inclusion %w[jpg jpeg png webp], message: "must be JPEG, PNG or WEBP"
      validate_max_size 5*1024*1024, message: "cannot be larger than 5MB"
      validate_min_size 5*1024, message: "cannot be smaller than 5KB"
      validate_min_dimensions [1280, 400], message: "must be larger than 1280 x 400 px"
    end
  end
end

I’m going through the exercise of creating a new Rails 7 API based on the existing application (using the same database in a read-only configuration) and I’d like to chop away anything I don’t need from the uploader(s) that I can.

For another example, I have a couple of other attachers that have a generate_location method in them. I presume I will not need those in order to read the generated location, since that becomes the key in the [attached item]_data hash.

Finally, my main lib/shrine.rb setup includes very little, but it does have the cached_attachment_data plugin defined:

# frozen_string_literal: true

require 'shrine'
require 'shrine/storage/s3'

Shrine.plugin(:activerecord)
Shrine.plugin(:cached_attachment_data)

s3_props = { public: true,
  bucket: 'oll-resources',
  region: 'us-east-2',
  access_key_id: ENV['AWS_KEY'],
  secret_access_key: ENV['AWS_SECRET']
}

Shrine.storages = {
  cache: Shrine::Storage::S3.new( prefix: 'oll3/cache', **s3_props),
  store: Shrine::Storage::S3.new( prefix: 'oll3/store', **s3_props),
}

Could I (should I) chop out the references to the cache from there, since those are only relevant when creating new attachments?

Thanks very much for your thoughts and suggestions.

Walter