Class: Vidibus::Tempfile

Inherits:
Tempfile
  • Object
show all
Defined in:
lib/vidibus/tempfile.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, tmpdir = Dir::tmpdir) ⇒ Tempfile

Returns a new instance of Tempfile.



3
4
5
6
7
8
# File 'lib/vidibus/tempfile.rb', line 3

def initialize(path, tmpdir = Dir::tmpdir)
  @original_filename = File.basename(path)
  @path = path
  super(@original_filename, tmpdir)
  fetch
end

Instance Method Details

#content_typeObject



21
22
23
24
25
26
# File 'lib/vidibus/tempfile.rb', line 21

def content_type
  mime = `file --mime -br #{self.path}`.strip
  mime.gsub!(/^.*: */,"")
  mime.gsub!(/(;|,).*$/,"")
  mime
end

#fetchObject



10
11
12
13
14
15
# File 'lib/vidibus/tempfile.rb', line 10

def fetch
  return unless File.file?(@path)
  self.write(File.read(@path))
  self.rewind
  self
end

#make_tmpname(basename, n) ⇒ Object

Replaces Tempfile’s make_tmpname with one that honors file extensions. Copied from Paperclip



30
31
32
33
# File 'lib/vidibus/tempfile.rb', line 30

def make_tmpname(basename, n)
  extension = File.extname(basename)
  sprintf("%s,%d,%d%s", File.basename(basename, extension), $$, n.to_i, extension)
end

#original_filenameObject



17
18
19
# File 'lib/vidibus/tempfile.rb', line 17

def original_filename
  @original_filename
end