aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/app/models/active_storage/blob.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2019-03-28 18:47:42 -0400
committerGeorge Claghorn <george@basecamp.com>2019-03-28 18:47:42 -0400
commit562f3a2d21de52872ccd9a2c8b734e30ec63430b (patch)
tree54b75b83739e9efa3d19a0f88ed3b1f5193fe367 /activestorage/app/models/active_storage/blob.rb
parente3f5f1c936869b81b01835adc9c683e058edfeaf (diff)
downloadrails-562f3a2d21de52872ccd9a2c8b734e30ec63430b.tar.gz
rails-562f3a2d21de52872ccd9a2c8b734e30ec63430b.tar.bz2
rails-562f3a2d21de52872ccd9a2c8b734e30ec63430b.zip
Add ActiveStorage::Service#open
Diffstat (limited to 'activestorage/app/models/active_storage/blob.rb')
-rw-r--r--activestorage/app/models/active_storage/blob.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb
index 6ca7d49bc1..38757d8f92 100644
--- a/activestorage/app/models/active_storage/blob.rb
+++ b/activestorage/app/models/active_storage/blob.rb
@@ -193,17 +193,18 @@ class ActiveStorage::Blob < ActiveRecord::Base
#
# The tempfile's name is prefixed with +ActiveStorage-+ and the blob's ID. Its extension matches that of the blob.
#
- # By default, the tempfile is created in <tt>Dir.tmpdir</tt>. Pass +tempdir:+ to create it in a different directory:
+ # By default, the tempfile is created in <tt>Dir.tmpdir</tt>. Pass +tmpdir:+ to create it in a different directory:
#
- # blob.open(tempdir: "/path/to/tmp") do |file|
+ # blob.open(tmpdir: "/path/to/tmp") do |file|
# # ...
# end
#
# The tempfile is automatically closed and unlinked after the given block is executed.
#
# Raises ActiveStorage::IntegrityError if the downloaded data does not match the blob's checksum.
- def open(tempdir: nil, &block)
- ActiveStorage::Downloader.new(self, tempdir: tempdir).download_blob_to_tempfile(&block)
+ def open(tmpdir: nil, &block)
+ service.open key, checksum: checksum,
+ name: [ "ActiveStorage-#{id}-", filename.extension_with_delimiter ], tmpdir: tmpdir, &block
end