Wraps a set of mirror services and provides a single ActiveStorage::Service object that will all have the files uploaded to them. A primary service is designated to answer calls to download, exists?, and url.

Methods

Attributes

[R] mirrors
[R] primary

Class Public methods

new(primary:, mirrors:)

📝 Source code
# File activestorage/lib/active_storage/service/mirror_service.rb, line 21
    def initialize(primary:, mirrors:)
      @primary, @mirrors = primary, mirrors
    end
🔎 See on GitHub

Instance Public methods

delete(key)

Delete the file at the key on all services.

📝 Source code
# File activestorage/lib/active_storage/service/mirror_service.rb, line 34
    def delete(key)
      perform_across_services :delete, key
    end
🔎 See on GitHub

delete_prefixed(prefix)

Delete files at keys starting with the prefix on all services.

📝 Source code
# File activestorage/lib/active_storage/service/mirror_service.rb, line 39
    def delete_prefixed(prefix)
      perform_across_services :delete_prefixed, prefix
    end
🔎 See on GitHub

upload(key, io, checksum: nil, **options)

Upload the io to the key specified to all services. If a checksum is provided, all services will ensure a match when the upload has completed or raise an ActiveStorage::IntegrityError.

📝 Source code
# File activestorage/lib/active_storage/service/mirror_service.rb, line 27
    def upload(key, io, checksum: nil, **options)
      each_service.collect do |service|
        service.upload key, io.tap(&:rewind), checksum: checksum, **options
      end
    end
🔎 See on GitHub