aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2017-11-02 15:07:04 -0400
committerGeorge Claghorn <george@basecamp.com>2017-11-02 15:07:41 -0400
commitaa6bcbbac8517d5b077f21073e9902637d7c7157 (patch)
treee12472825cf46e5458af656564f3bd23814aab08
parent97f317e8ffe823155e37dcdd9ccf3822c3e86f3c (diff)
downloadrails-aa6bcbbac8517d5b077f21073e9902637d7c7157.tar.gz
rails-aa6bcbbac8517d5b077f21073e9902637d7c7157.tar.bz2
rails-aa6bcbbac8517d5b077f21073e9902637d7c7157.zip
Allow third-party previewers/analyzers to customize their tempdirs
-rw-r--r--activestorage/lib/active_storage/downloading.rb9
-rw-r--r--activestorage/lib/active_storage/previewer.rb4
2 files changed, 10 insertions, 3 deletions
diff --git a/activestorage/lib/active_storage/downloading.rb b/activestorage/lib/active_storage/downloading.rb
index ceb7cce0c7..3dac6b116a 100644
--- a/activestorage/lib/active_storage/downloading.rb
+++ b/activestorage/lib/active_storage/downloading.rb
@@ -3,9 +3,9 @@
module ActiveStorage
module Downloading
private
- # Opens a new tempfile and copies blob data into it. Yields the tempfile.
+ # Opens a new tempfile in #tempdir and copies blob data into it. Yields the tempfile.
def download_blob_to_tempfile # :doc:
- Tempfile.open("ActiveStorage") do |file|
+ Tempfile.open("ActiveStorage", tempdir) do |file|
download_blob_to file
yield file
end
@@ -17,5 +17,10 @@ module ActiveStorage
blob.download { |chunk| file.write(chunk) }
file.rewind
end
+
+ # Returns the directory in which tempfiles should be opened. Defaults to +Dir.tmpdir+.
+ def tempdir # :doc:
+ Dir.tmpdir
+ end
end
end
diff --git a/activestorage/lib/active_storage/previewer.rb b/activestorage/lib/active_storage/previewer.rb
index 460f6d5678..ed75bae3b5 100644
--- a/activestorage/lib/active_storage/previewer.rb
+++ b/activestorage/lib/active_storage/previewer.rb
@@ -40,8 +40,10 @@ module ActiveStorage
# end
# end
# end
+ #
+ # The output tempfile is opened in the directory returned by ActiveStorage::Downloading#tempdir.
def draw(*argv) # :doc:
- Tempfile.open("ActiveStorage") do |file|
+ Tempfile.open("ActiveStorage", tempdir) do |file|
capture(*argv, to: file)
yield file
end