diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-22 09:47:24 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-22 09:47:24 -0500 |
commit | d50679f4eefde1aca1ab71ba3c0109739cfdff3f (patch) | |
tree | ac9034fe7c4aa64cd5e90ecebc346d478917387c /app/models/active_storage/attachment.rb | |
parent | 5b7c31c23a708de77b3d73b68aec0ba99c8be861 (diff) | |
download | rails-d50679f4eefde1aca1ab71ba3c0109739cfdff3f.tar.gz rails-d50679f4eefde1aca1ab71ba3c0109739cfdff3f.tar.bz2 rails-d50679f4eefde1aca1ab71ba3c0109739cfdff3f.zip |
Move models and jobs to the app setup
Follow engine conventions more closely
Diffstat (limited to 'app/models/active_storage/attachment.rb')
-rw-r--r-- | app/models/active_storage/attachment.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/models/active_storage/attachment.rb b/app/models/active_storage/attachment.rb new file mode 100644 index 0000000000..20c619aa5a --- /dev/null +++ b/app/models/active_storage/attachment.rb @@ -0,0 +1,30 @@ +require "active_storage/blob" +require "global_id" +require "active_support/core_ext/module/delegation" + +# Schema: id, record_gid, blob_id, created_at +class ActiveStorage::Attachment < ActiveRecord::Base + self.table_name = "active_storage_attachments" + + belongs_to :blob, class_name: "ActiveStorage::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 + end + + def purge_later + ActiveStorage::PurgeJob.perform_later(self) + end +end |