diff options
Diffstat (limited to 'activestorage/app/models')
-rw-r--r-- | activestorage/app/models/active_storage/attachment.rb | 10 | ||||
-rw-r--r-- | activestorage/app/models/active_storage/blob.rb | 4 | ||||
-rw-r--r-- | activestorage/app/models/active_storage/filename.rb | 18 |
3 files changed, 19 insertions, 13 deletions
diff --git a/activestorage/app/models/active_storage/attachment.rb b/activestorage/app/models/active_storage/attachment.rb index ad43845e4e..2a1c20b7db 100644 --- a/activestorage/app/models/active_storage/attachment.rb +++ b/activestorage/app/models/active_storage/attachment.rb @@ -14,17 +14,15 @@ class ActiveStorage::Attachment < ActiveRecord::Base delegate_missing_to :blob - # Purging an attachment will purge the blob (delete the file on the service, then destroy the record) - # and then destroy the attachment itself. + # Synchronously purges the blob (deletes it from the configured service) and destroys the attachment. def purge blob.purge destroy end - # Purging an attachment means purging the blob, which means talking to the service, which means - # talking over the Internet. Whenever you're doing that, it's a good idea to put that work in a job, - # so it doesn't hold up other operations. That's what +purge_later+ provides. + # Destroys the attachment and asynchronously purges the blob (deletes it from the configured service). def purge_later - ActiveStorage::PurgeJob.perform_later(self) + blob.purge_later + destroy end end diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb index 664a53a778..e6cf08ce83 100644 --- a/activestorage/app/models/active_storage/blob.rb +++ b/activestorage/app/models/active_storage/blob.rb @@ -3,8 +3,8 @@ # A blob is a record that contains the metadata about a file and a key for where that file resides on the service. # Blobs can be created in two ways: # -# 1) Subsequent to the file being uploaded server-side to the service via <tt>create_after_upload!</tt>. -# 2) Ahead of the file being directly uploaded client-side to the service via <tt>create_before_direct_upload!</tt>. +# 1. Subsequent to the file being uploaded server-side to the service via <tt>create_after_upload!</tt>. +# 2. Ahead of the file being directly uploaded client-side to the service via <tt>create_before_direct_upload!</tt>. # # The first option doesn't require any client-side JavaScript integration, and can be used by any other back-end # service that deals with files. The second option is faster, since you're not using your own server as a staging diff --git a/activestorage/app/models/active_storage/filename.rb b/activestorage/app/models/active_storage/filename.rb index 10b1116d52..dead6b6d33 100644 --- a/activestorage/app/models/active_storage/filename.rb +++ b/activestorage/app/models/active_storage/filename.rb @@ -9,25 +9,33 @@ class ActiveStorage::Filename @filename = filename end - # Filename.new("racecar.jpg").base # => "racecar" + # Returns the basename of the filename. + # + # ActiveStorage::Filename.new("racecar.jpg").base # => "racecar" def base File.basename @filename, extension_with_delimiter end - # Filename.new("racecar.jpg").extension_with_delimiter # => ".jpg" + # Returns the extension with delimiter of the filename. + # + # ActiveStorage::Filename.new("racecar.jpg").extension_with_delimiter # => ".jpg" def extension_with_delimiter File.extname @filename end - # Filename.new("racecar.jpg").extension_without_delimiter # => "jpg" + # Returns the extension without delimiter of the filename. + # + # ActiveStorage::Filename.new("racecar.jpg").extension_without_delimiter # => "jpg" def extension_without_delimiter extension_with_delimiter.from(1).to_s end alias_method :extension, :extension_without_delimiter - # Filename.new("foo:bar.jpg").sanitized # => "foo-bar.jpg" - # Filename.new("foo/bar.jpg").sanitized # => "foo-bar.jpg" + # Returns the sanitized filename. + # + # ActiveStorage::Filename.new("foo:bar.jpg").sanitized # => "foo-bar.jpg" + # ActiveStorage::Filename.new("foo/bar.jpg").sanitized # => "foo-bar.jpg" # # ...and any other character unsafe for URLs or storage is converted or stripped. def sanitized |