Which directory is preferred for its own storage?

Hello!

I want to create own storage, which directory is best?

I’m using framework Ruby on Rails.

I placed it in app/uploader/storage/test_storage.rb and received a warning

# app/uploader/storage/my_storage.rb

module Storage
  class MyStorage < Shrine::Storage::S3
      def url(id, **options)
        # returns URL to the remote file, can accept URL options
      end
  end
end
# shrine.rb
  require "shrine/storage/s3"

  s3_options = {
     *******************
  }

  Shrine.storages = {
    my_store: Storage::MyStorage.new(prefix: 'store/my', **s3_options),
  }
Being able to do this is deprecated. Autoloading during initialization is going to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during initialization does not run again. So, if you reload Storage, for example, the expected changes won't be reflected in that stale Module object.

These autoloaded constants have been unloaded.

In order to autoload safely at boot time, please wrap your code in a reloader

allback this way:

Rails.application.reloader.to_prepare do
  # Autoload classes and modules needed at boot time here.
end

That block runs when the application boots, and every time there is a reload.

For historical reasons, it may run twice, so it has to be idempotent.

Check the "Autoloading and Reloading Constants" guide to learn more about how Rails autoloads and reloads.

You might want to use the lib/ directory instead, which is not added to Zeitwerk’s autoload paths by default. I think lib/ is automatically added to the load path, so if you place the storage at lib/shrine/storages/test_storage.rb, you should be able to require it via require "shrine/storage/test_storage" in the Shrine initializer, and avoid this issue.