Class: ActiveStorage::Service::CascadeService
- Inherits:
-
ActiveStorage::Service
- Object
- ActiveStorage::Service
- ActiveStorage::Service::CascadeService
- Defined in:
- lib/active_storage/service/cascade_service.rb
Instance Attribute Summary collapse
-
#primary ⇒ Object
readonly
Returns the value of attribute primary.
-
#secondaries ⇒ Object
readonly
Returns the value of attribute secondaries.
Class Method Summary collapse
Instance Method Summary collapse
-
#download(key) ⇒ Object
Return the content of the file at the
key
. -
#download_chunk(key, range) ⇒ Object
Return the partial content in the byte
range
of the file at thekey
. -
#exist?(key) ⇒ Boolean
Return
true
if a file exists at thekey
. -
#initialize(primary:, secondaries:) ⇒ CascadeService
constructor
A new instance of CascadeService.
- #method_missing(method_name, *arguments, &block) ⇒ Object
- #respond_to?(method_name, include_private = false) ⇒ Boolean
-
#url(key, expires_in:, disposition:, filename:, content_type:) ⇒ Object
Returns a signed, temporary URL for the file at the
key
.
Constructor Details
#initialize(primary:, secondaries:) ⇒ CascadeService
Returns a new instance of CascadeService.
20 21 22 23 |
# File 'lib/active_storage/service/cascade_service.rb', line 20 def initialize(primary:, secondaries:) @primary = primary @secondaries = secondaries end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/active_storage/service/cascade_service.rb', line 48 def method_missing(method_name, *arguments, &block) if primary.respond_to?(method_name) primary.send(method_name, *arguments, &block) else super end end |
Instance Attribute Details
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
8 9 10 |
# File 'lib/active_storage/service/cascade_service.rb', line 8 def primary @primary end |
#secondaries ⇒ Object (readonly)
Returns the value of attribute secondaries.
8 9 10 |
# File 'lib/active_storage/service/cascade_service.rb', line 8 def secondaries @secondaries end |
Class Method Details
.build(primary:, secondaries:, configurator:, **_options) ⇒ Object
:nodoc:
13 14 15 16 17 18 |
# File 'lib/active_storage/service/cascade_service.rb', line 13 def self.build(primary:, secondaries:, configurator:, **) #:nodoc: new( primary: configurator.build(primary), secondaries: configurator.build(secondaries) ) end |
Instance Method Details
#download(key) ⇒ Object
Return the content of the file at the key
.
26 27 28 |
# File 'lib/active_storage/service/cascade_service.rb', line 26 def download(key) service(key).download(key) end |
#download_chunk(key, range) ⇒ Object
Return the partial content in the byte range
of the file at the key
.
31 32 33 |
# File 'lib/active_storage/service/cascade_service.rb', line 31 def download_chunk(key, range) service(key).download_chunk(key, range) end |
#exist?(key) ⇒ Boolean
Return true
if a file exists at the key
.
36 37 38 |
# File 'lib/active_storage/service/cascade_service.rb', line 36 def exist?(key) [primary, *secondaries].any? { |svc| svc.exist?(key) } end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
56 57 58 |
# File 'lib/active_storage/service/cascade_service.rb', line 56 def respond_to?(method_name, include_private = false) primary.respond_to?(method_name, include_private) || super end |
#url(key, expires_in:, disposition:, filename:, content_type:) ⇒ Object
Returns a signed, temporary URL for the file at the key
. The URL will be valid for the amount of seconds specified in expires_in
. You most also provide the disposition
(:inline
or :attachment
), filename
, and content_type
that you wish the file to be served with on request.
43 44 45 46 |
# File 'lib/active_storage/service/cascade_service.rb', line 43 def url(key, expires_in:, disposition:, filename:, content_type:) service(key) .url(key, expires_in: expires_in, disposition: disposition, filename: filename, content_type: content_type) end |