module FileBlobs::BlobModel
Included in the model that stores file data.
Public Instance Methods
eligible_for_garbage_collection?()
click to toggle source
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.
@return [Boolean] true if this blob is not referenced by any Blob-owning
model, and thus is eligible for garbage collection
# 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()
click to toggle source
Garbage-collects this blob if it is not referenced by any other model.
@return [Boolean] true if the blob was garbage-collected
# 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