Sha256: 394ca132e82d89ab61e7e0a7e527a48974144a6988566b6097e29dde887de022

Contents?: true

Size: 1.34 KB

Versions: 14

Compression:

Stored size: 1.34 KB

Contents

module Paperclip
  # Overriding some implementation of Tempfile
  class Tempfile < ::Tempfile
    # 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:
    # http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
    #
    # This is Ruby 1.9.3's implementation.
    def make_tmpname(prefix_suffix, n)
      if RUBY_PLATFORM =~ /java/
        case prefix_suffix
        when String
          prefix = prefix_suffix
          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
  end

  module TempfileEncoding
    # This overrides Tempfile#binmode to make sure that the extenal encoding
    # for binary mode is ASCII-8BIT. This behavior is what's in CRuby, but not
    # in JRuby
    def binmode
      set_encoding("ASCII-8BIT")
      super
    end
  end
end

::Tempfile.include Paperclip::TempfileEncoding if RUBY_PLATFORM =~ /java/

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kt-paperclip-7.2.2 lib/paperclip/tempfile.rb
kt-paperclip-7.2.1 lib/paperclip/tempfile.rb
kt-paperclip-7.2.0 lib/paperclip/tempfile.rb
kt-paperclip-6.4.2 lib/paperclip/tempfile.rb
kt-paperclip-7.1.1 lib/paperclip/tempfile.rb
kt-paperclip-7.1.0 lib/paperclip/tempfile.rb
kt-paperclip-7.0.1 lib/paperclip/tempfile.rb
kt-paperclip-7.0.0 lib/paperclip/tempfile.rb
kt-paperclip-6.4.1 lib/paperclip/tempfile.rb
kt-paperclip-6.4.0 lib/paperclip/tempfile.rb
kt-paperclip-6.3.0 lib/paperclip/tempfile.rb
kt-paperclip-6.2.2 lib/paperclip/tempfile.rb
kt-paperclip-6.2.1 lib/paperclip/tempfile.rb
kt-paperclip-6.2.0 lib/paperclip/tempfile.rb