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.
-
#initialize(primary:, mirrors:) ⇒ MirrorService
constructor
A new instance of MirrorService.
-
#upload(key, io, checksum: nil) ⇒ Object
Upload the ‘io` to the `key` specified to all services.
Methods inherited from ActiveStorage::Service
configure, #download, #exist?, #headers_for_direct_upload, #url, #url_for_direct_upload
Constructor Details
#initialize(primary:, mirrors:) ⇒ MirrorService
Returns a new instance of MirrorService.
18 19 20 |
# File 'lib/active_storage/service/mirror_service.rb', line 18 def initialize(primary:, mirrors:) @primary, @mirrors = primary, mirrors end |
Instance Attribute Details
#mirrors ⇒ Object (readonly)
Returns the value of attribute mirrors.
7 8 9 |
# File 'lib/active_storage/service/mirror_service.rb', line 7 def mirrors @mirrors end |
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
7 8 9 |
# File 'lib/active_storage/service/mirror_service.rb', line 7 def primary @primary end |
Class Method Details
.build(primary:, mirrors:, configurator:, **options) ⇒ Object
Stitch together from named services.
12 13 14 15 16 |
# File 'lib/active_storage/service/mirror_service.rb', line 12 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.
31 32 33 |
# File 'lib/active_storage/service/mirror_service.rb', line 31 def delete(key) perform_across_services :delete, key end |
#upload(key, io, checksum: nil) ⇒ 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`.
24 25 26 27 28 |
# File 'lib/active_storage/service/mirror_service.rb', line 24 def upload(key, io, checksum: nil) each_service.collect do |service| service.upload key, io.tap(&:rewind), checksum: checksum end end |