From eefbdc2b9eb19d48b22475d11bbb87988c54475e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 5 Jul 2017 18:30:00 +0200 Subject: Only purge if attached --- lib/active_vault/attached/many.rb | 13 +++++++++++-- lib/active_vault/attached/one.rb | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'lib/active_vault') 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 -- cgit v1.2.3