Class: Attach::Backends::Database
Instance Method Summary
collapse
Methods inherited from Abstract
#bytesize, #digest, #initialize, #read_multi, #url
Instance Method Details
#delete(attachment) ⇒ Object
25
26
27
|
# File 'lib/attach/backends/database.rb', line 25
def delete(attachment)
AttachmentBinary.where(attachment_id: attachment.id).destroy_all
end
|
#read(attachment) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/attach/backends/database.rb', line 11
def read(attachment)
binary = AttachmentBinary.find_by(attachment_id: attachment.id)
return if binary.nil?
BlobTypes::Raw.new(binary.data)
end
|
#write(attachment, blob) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/attach/backends/database.rb', line 18
def write(attachment, blob)
binary_object = AttachmentBinary.where(attachment_id: attachment.id).first_or_initialize
binary_object.data = blob.read
binary_object.save!
binary_object
end
|