aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_vault
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2017-07-05 18:30:00 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2017-07-05 18:31:53 +0200
commiteefbdc2b9eb19d48b22475d11bbb87988c54475e (patch)
tree2d9ea44ed27fe89e3da7babda912f129a159065c /lib/active_vault
parent7d3955e6f7c9a38a226dff81bb9b436bae91590d (diff)
downloadrails-eefbdc2b9eb19d48b22475d11bbb87988c54475e.tar.gz
rails-eefbdc2b9eb19d48b22475d11bbb87988c54475e.tar.bz2
rails-eefbdc2b9eb19d48b22475d11bbb87988c54475e.zip
Only purge if attached
Diffstat (limited to 'lib/active_vault')
-rw-r--r--lib/active_vault/attached/many.rb13
-rw-r--r--lib/active_vault/attached/one.rb13
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/active_vault/attached/many.rb b/lib/active_vault/attached/many.rb
index 83fab12385..6f79a1c555 100644
--- a/lib/active_vault/attached/many.rb
+++ b/lib/active_vault/attached/many.rb
@@ -16,7 +16,16 @@ class ActiveVault::Attached::Many < ActiveVault::Attached
end
def purge
- attachments.each(&:purge)
- @attachments = nil
+ if attached?
+ attachments.each(&:purge)
+ @attachments = nil
+ end
+ end
+
+ def purge_later
+ if attached?
+ attachments.each(&:purge_later)
+ @attachments = nil
+ end
end
end
diff --git a/lib/active_vault/attached/one.rb b/lib/active_vault/attached/one.rb
index 5566c1b971..9bf83254c0 100644
--- a/lib/active_vault/attached/one.rb
+++ b/lib/active_vault/attached/one.rb
@@ -18,7 +18,16 @@ class ActiveVault::Attached::One < ActiveVault::Attached
end
def purge
- attachment.purge
- @attachment = nil
+ if attached?
+ attachment.purge
+ @attachment = nil
+ end
+ end
+
+ def purge_later
+ if attached?
+ attachment.purge_later
+ @attachment = nil
+ end
end
end