From 9f95767979579f5761cb0d2bcccb67f3662349c5 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Thu, 17 May 2018 19:14:11 -0400 Subject: Permit opening a blob in a custom tempdir --- activestorage/lib/active_storage/analyzer.rb | 6 +++++- activestorage/lib/active_storage/downloader.rb | 11 ++++++----- activestorage/lib/active_storage/previewer.rb | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) (limited to 'activestorage/lib/active_storage') diff --git a/activestorage/lib/active_storage/analyzer.rb b/activestorage/lib/active_storage/analyzer.rb index 8dcfb9d7bd..caa25418a5 100644 --- a/activestorage/lib/active_storage/analyzer.rb +++ b/activestorage/lib/active_storage/analyzer.rb @@ -24,11 +24,15 @@ module ActiveStorage private # Downloads the blob to a tempfile on disk. Yields the tempfile. def download_blob_to_tempfile(&block) #:doc: - blob.open(&block) + blob.open tempdir: tempdir, &block end def logger #:doc: ActiveStorage.logger end + + def tempdir #:doc: + Dir.tmpdir + end end end diff --git a/activestorage/lib/active_storage/downloader.rb b/activestorage/lib/active_storage/downloader.rb index 7f5b4936a5..0e7039e104 100644 --- a/activestorage/lib/active_storage/downloader.rb +++ b/activestorage/lib/active_storage/downloader.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true module ActiveStorage - class Downloader - def initialize(blob) - @blob = blob + class Downloader #:nodoc: + def initialize(blob, tempdir: nil) + @blob = blob + @tempdir = tempdir end def download_blob_to_tempfile @@ -14,10 +15,10 @@ module ActiveStorage end private - attr_reader :blob + attr_reader :blob, :tempdir def open_tempfile - file = Tempfile.open([ "ActiveStorage", tempfile_extension_with_delimiter ]) + file = Tempfile.open([ "ActiveStorage", tempfile_extension_with_delimiter ], tempdir) begin yield file diff --git a/activestorage/lib/active_storage/previewer.rb b/activestorage/lib/active_storage/previewer.rb index f09dc25879..bff5e42d41 100644 --- a/activestorage/lib/active_storage/previewer.rb +++ b/activestorage/lib/active_storage/previewer.rb @@ -26,7 +26,7 @@ module ActiveStorage private # Downloads the blob to a tempfile on disk. Yields the tempfile. def download_blob_to_tempfile(&block) #:doc: - blob.open(&block) + blob.open tempdir: tempdir, &block end # Executes a system command, capturing its binary output in a tempfile. Yields the tempfile. -- cgit v1.2.3