Module: FileBlobs::BlobModel
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/file_blobs_rails/blob_model.rb
Overview
Included in the model that stores file data.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#eligible_for_garbage_collection? ⇒ Boolean
Checks if this blob can be garbage-collected.
-
#maybe_garbage_collect ⇒ Boolean
Garbage-collects this blob if it is not referenced by any other model.
Instance Method Details
#eligible_for_garbage_collection? ⇒ Boolean
Checks if this blob can be garbage-collected.
This check’s result can become invalid after another Blob-owning model is created. To prevent data races, the check and its corresponding garbage collection must be done in the same database transaction.
99 100 101 102 103 |
# File 'lib/file_blobs_rails/blob_model.rb', line 99 def eligible_for_garbage_collection? self.class.blob_owner_classes.all? do |klass| klass.file_blob_eligible_for_garbage_collection? self end end |
#maybe_garbage_collect ⇒ Boolean
Garbage-collects this blob if it is not referenced by any other model.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/file_blobs_rails/blob_model.rb', line 80 def maybe_garbage_collect self.class.transaction do if eligible_for_garbage_collection? destroy true else false end end end |