diff options
Diffstat (limited to 'lib/active_vault/attachment.rb')
-rw-r--r-- | lib/active_vault/attachment.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/active_vault/attachment.rb b/lib/active_vault/attachment.rb new file mode 100644 index 0000000000..eb108e9cbb --- /dev/null +++ b/lib/active_vault/attachment.rb @@ -0,0 +1,27 @@ +require "active_vault/blob" +require "global_id" +require "active_support/core_ext/module/delegation" + +# Schema: id, record_gid, blob_id, created_at +class ActiveVault::Attachment < ActiveRecord::Base + self.table_name = "active_vault_attachments" + + belongs_to :blob, class_name: "ActiveVault::Blob" + + delegate_missing_to :blob + + def record + @record ||= GlobalID::Locator.locate(record_gid) + end + + def record=(record) + @record = record + self.record_gid = record&.to_gid + end + + def purge + blob.purge + destroy + record.public_send "#{name}=", nil + end +end |