Class: ActiveStorage::Service::MirrorService
- Inherits:
-
ActiveStorage::Service
- Object
- ActiveStorage::Service
- ActiveStorage::Service::MirrorService
- Defined in:
- lib/active_storage/service/mirror_service.rb
Overview
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
.
Instance Attribute Summary collapse
-
#mirrors ⇒ Object
readonly
Returns the value of attribute mirrors.
-
#primary ⇒ Object
readonly
Returns the value of attribute primary.
Class Method Summary collapse
-
.build(primary:, mirrors:, configurator:, **options) ⇒ Object
Stitch together from named services.
Instance Method Summary collapse
-
#delete(key) ⇒ Object
Delete the file at the
key
on all services. -
#delete_prefixed(prefix) ⇒ Object
Delete files at keys starting with the
prefix
on all services. -
#initialize(primary:, mirrors:) ⇒ MirrorService
constructor
A new instance of MirrorService.
-
#upload(key, io, checksum: nil, **options) ⇒ Object
Upload the
io
to thekey
specified to all services.
Methods inherited from ActiveStorage::Service
configure, #download, #download_chunk, #exist?, #headers_for_direct_upload, #update_metadata, #url, #url_for_direct_upload
Constructor Details
#initialize(primary:, mirrors:) ⇒ MirrorService
Returns a new instance of MirrorService.
21 22 23 |
# File 'lib/active_storage/service/mirror_service.rb', line 21 def initialize(primary:, mirrors:) @primary, @mirrors = primary, mirrors end |
Instance Attribute Details
#mirrors ⇒ Object (readonly)
Returns the value of attribute mirrors.
10 11 12 |
# File 'lib/active_storage/service/mirror_service.rb', line 10 def mirrors @mirrors end |
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
10 11 12 |
# File 'lib/active_storage/service/mirror_service.rb', line 10 def primary @primary end |
Class Method Details
.build(primary:, mirrors:, configurator:, **options) ⇒ Object
Stitch together from named services.
15 16 17 18 19 |
# File 'lib/active_storage/service/mirror_service.rb', line 15 def self.build(primary:, mirrors:, configurator:, **) #:nodoc: new \ primary: configurator.build(primary), mirrors: mirrors.collect { |name| configurator.build name } end |
Instance Method Details
#delete(key) ⇒ Object
Delete the file at the key
on all services.
34 35 36 |
# File 'lib/active_storage/service/mirror_service.rb', line 34 def delete(key) perform_across_services :delete, key end |
#delete_prefixed(prefix) ⇒ Object
Delete files at keys starting with the prefix
on all services.
39 40 41 |
# File 'lib/active_storage/service/mirror_service.rb', line 39 def delete_prefixed(prefix) perform_across_services :delete_prefixed, prefix end |
#upload(key, io, checksum: nil, **options) ⇒ Object
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.
27 28 29 30 31 |
# File 'lib/active_storage/service/mirror_service.rb', line 27 def upload(key, io, checksum: nil, **) each_service.collect do |service| service.upload key, io.tap(&:rewind), checksum: checksum, ** end end |