123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- class UploadCache
- attr_reader :id
-
-
-
-
-
-
- def initialize(id)
- @id = id
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- def add(args)
- Store.create!(
- args.merge(
- object: store_object,
- o_id: id,
- )
- )
- end
-
-
-
-
-
-
-
-
- def attachments
- Store.list(
- object: store_object,
- o_id: id,
- )
- end
-
-
-
-
-
-
-
- def destroy
- Store.remove(
- object: store_object,
- o_id: id,
- )
- end
-
-
-
-
-
-
-
-
-
- def remove_item(store_id = nil)
- store = Store.find(store_id)
- if store.o_id != id || store.store_object_id != store_object_id
- raise Exceptions::UnprocessableEntity, "Attempt to delete Store item #{store_id} that is not bound to UploadCache object"
- end
- Store.remove_item(store_id)
- end
-
-
-
-
-
-
-
- def self.files_include_attachment?(files, single_attachment)
- files.any? { |elem| attachment_matches?(single_attachment, elem) }
- end
- private
- def store_object
- self.class.name
- end
- def store_object_id
- Store::Object.lookup(name: store_object).id
- end
-
-
-
-
- def self.attachment_matches?(attachment, file)
- return false if file[:name] != attachment.filename
- attachment_content_type = attachment.preferences['Content-Type']
- if file[:type].blank? || attachment_content_type.blank?
- return true
- end
- file[:type] == attachment_content_type
- end
- private_class_method :attachment_matches?
- end
|