Class: LaserBlob::Attachment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/laserblob/attachment.rb

Instance Method Summary collapse

Instance Method Details

#default_filenameObject



32
33
34
# File 'app/models/laserblob/attachment.rb', line 32

def default_filename
  self.filename ||= [self.type, SecureRandom.hex(10)].join("-")
end

#file=(file) ⇒ Object



21
22
23
24
# File 'app/models/laserblob/attachment.rb', line 21

def file=(file)
  self.filename ||= LaserBlob::BlobHelpers.filename_from_file(file)
  self.blob = LaserBlob::Blob.new(file: file)
end

#open(basename: nil, &block) ⇒ Object



36
37
38
39
# File 'app/models/laserblob/attachment.rb', line 36

def open(basename: nil, &block)
  basename ||= [File.basename(filename), File.extname(filename)]
  blob.open(basename: basename, &block)
end

#url(**options) ⇒ Object



16
17
18
19
# File 'app/models/laserblob/attachment.rb', line 16

def url(**options)
  options[:filename] ||= filename
  blob.url(**options)
end

#url=(url) ⇒ Object



26
27
28
29
30
# File 'app/models/laserblob/attachment.rb', line 26

def url=(url)
  file = LaserBlob::Blob.download_url(url)
  self.filename = file.original_filename
  self.blob = LaserBlob::Blob.create!(file: file)
end