module ActiveStorage::Downloading

Public Class Methods

included(klass) click to toggle source
# File lib/active_storage/downloading.rb, line 7
    def self.included(klass)
      ActiveSupport::Deprecation.warn <<~MESSAGE.squish, caller_locations(2)
        ActiveStorage::Downloading is deprecated and will be removed in Active Storage 6.1.
        Use ActiveStorage::Blob#open instead.
      MESSAGE
    end

Private Instance Methods

download_blob_to(file) click to toggle source

Efficiently downloads blob data into the given file.

# File lib/active_storage/downloading.rb, line 34
def download_blob_to(file) #:doc:
  file.binmode
  blob.download { |chunk| file.write(chunk) }
  file.flush
  file.rewind
end
download_blob_to_tempfile() { |file| ... } click to toggle source

Opens a new tempfile in tempdir and copies blob data into it. Yields the tempfile.

# File lib/active_storage/downloading.rb, line 16
def download_blob_to_tempfile #:doc:
  open_tempfile_for_blob do |file|
    download_blob_to file
    yield file
  end
end
open_tempfile_for_blob() { |tempfile| ... } click to toggle source
# File lib/active_storage/downloading.rb, line 23
def open_tempfile_for_blob
  tempfile = Tempfile.open([ "ActiveStorage", blob.filename.extension_with_delimiter ], tempdir)

  begin
    yield tempfile
  ensure
    tempfile.close!
  end
end
tempdir() click to toggle source

Returns the directory in which tempfiles should be opened. Defaults to Dir.tmpdir.

# File lib/active_storage/downloading.rb, line 42
def tempdir #:doc:
  Dir.tmpdir
end