Class: Vidibus::Tempfile
- Inherits:
-
Tempfile
- Object
- Tempfile
- Vidibus::Tempfile
- Defined in:
- lib/vidibus/tempfile.rb
Instance Method Summary collapse
- #content_type ⇒ Object
- #fetch ⇒ Object
-
#initialize(path, tmpdir = Dir::tmpdir) ⇒ Tempfile
constructor
A new instance of Tempfile.
-
#make_tmpname(basename, n) ⇒ Object
Replaces Tempfile’s
make_tmpname
with one that honors file extensions. - #original_filename ⇒ Object
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_type ⇒ Object
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 |
#fetch ⇒ Object
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_filename ⇒ Object
17 18 19 |
# File 'lib/vidibus/tempfile.rb', line 17 def original_filename @original_filename end |