Class: Paperclip::Tempfile

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

Overview

Overriding some implementation of Tempfile

Instance Method Summary collapse

Instance Method Details

#make_tmpname(prefix_suffix, n) ⇒ Object

Due to how ImageMagick handles its image format conversion and how Tempfile handles its naming scheme, it is necessary to override how Tempfile makes # its names so as to allow for file extensions. Idea taken from the comments on this blog post: marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions

This is Ruby 1.9.3's implementation.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/paperclip/tempfile.rb', line 11

def make_tmpname(prefix_suffix, n)
  if RUBY_PLATFORM =~ /java/
    case prefix_suffix
    when String
      prefix, suffix = prefix_suffix, ''
    when Array
      prefix, suffix = *prefix_suffix
    else
      raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
    end

    t = Time.now.strftime("%y%m%d")
    path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}"
  else
    super
  end
end