class ZipPack < ApplicationRecord def self.packed?(bid, user_id, digests) zip_pack = ZipPack.where(container_id: bid.id, container_type: bid.class.to_s, user_id: user_id).first return false unless zip_pack && zip_pack.digests == digests zip_pack end def file_valid? return false unless File.exist?(self.file_path) Educoder::Utils.digest(self.file_path) == self.file_digest end def digests self.file_digests.split(',').sort end end