class ActiveStorageDownloader
Imported from the future github.com/rails/rails/commit/ee21b7c2eb64def8f00887a9fafbd77b85f464f1#diff-c76fb6202b7f95a08fe12f40c4999ac9
Attributes
blob[R]
tempdir[R]
Public Class Methods
new(blob, tempdir: nil)
click to toggle source
# File lib/clowne_active_storage/helpers/active_storage_downloader.rb, line 7 def initialize(blob, tempdir: nil) @blob = blob @tempdir = tempdir end
Public Instance Methods
download_blob_to_tempfile() { |file| ... }
click to toggle source
# File lib/clowne_active_storage/helpers/active_storage_downloader.rb, line 12 def download_blob_to_tempfile open_tempfile do |file| download_blob_to file verify_integrity_of file yield file end end
Private Instance Methods
download_blob_to(file)
click to toggle source
# File lib/clowne_active_storage/helpers/active_storage_downloader.rb, line 35 def download_blob_to(file) file.binmode blob.download { |chunk| file.write(chunk) } file.flush file.rewind end
open_tempfile() { |file| ... }
click to toggle source
# File lib/clowne_active_storage/helpers/active_storage_downloader.rb, line 22 def open_tempfile file = Tempfile.open( ["ActiveStorage-#{blob.id}-", blob.filename.extension_with_delimiter], tempdir ) begin yield file ensure file.close! end end
verify_integrity_of(file)
click to toggle source
# File lib/clowne_active_storage/helpers/active_storage_downloader.rb, line 42 def verify_integrity_of(file) return if Digest::MD5.file(file).base64digest == blob.checksum raise ActiveStorage::IntegrityError end