class ActiveStorage::Service::CascadeService

Attributes

primary[R]
secondaries[R]

Public Class Methods

new(primary:, secondaries:) click to toggle source
# File lib/active_storage/service/cascade_service.rb, line 20
def initialize(primary:, secondaries:)
  @primary = primary
  @secondaries = secondaries
end

Public Instance Methods

download(key) click to toggle source

Return the content of the file at the key.

# File lib/active_storage/service/cascade_service.rb, line 26
def download(key)
  service(key).download(key)
end
download_chunk(key, range) click to toggle source

Return the partial content in the byte range of the file at the key.

# File lib/active_storage/service/cascade_service.rb, line 31
def download_chunk(key, range)
  service(key).download_chunk(key, range)
end
exist?(key) click to toggle source

Return true if a file exists at the key.

# File lib/active_storage/service/cascade_service.rb, line 36
def exist?(key)
  [primary, *secondaries].any? { |svc| svc.exist?(key) }
end
method_missing(method_name, *arguments, &block) click to toggle source
Calls superclass method
# 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
respond_to?(method_name, include_private = false) click to toggle source
Calls superclass method
# 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:) click to toggle source

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.

# 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

Private Instance Methods

service(key) click to toggle source
# File lib/active_storage/service/cascade_service.rb, line 62
def service(key)
  [primary, *secondaries].find { |svc| svc.exist?(key) }
end