module LearningObject::DuplicateAttachmentChecker def self.check_duplicates(learning_object, media_path) file_size = File.size media_path file_name = File.basename media_path learning_object.attachments.each do |learning_object| if attachment.size == file_size && attachment.name == file_name return true end end end def self.check_duplicates!(learning_object, media_path) if check_duplicates learning_object, media_path raise DuplicateAttachmentError, 'The attachment already exists!' end end end