Sha256: 27a1a59a9485d93ae1115b9ab6767659ae8dd633eb4657135a19e2e636a5c3c7

Contents?: true

Size: 1.34 KB

Versions: 53

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, 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
  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

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

Version data entries

53 entries across 51 versions & 6 rubygems

Version Path
kt-paperclip-5.4.0 lib/paperclip/tempfile.rb
kt-paperclip-4.4.0 lib/paperclip/tempfile.rb
paperclip-6.1.0 lib/paperclip/tempfile.rb
paperclip-6.0.0 lib/paperclip/tempfile.rb
paperclip-5.3.0 lib/paperclip/tempfile.rb
paperclip-5.2.1 lib/paperclip/tempfile.rb
paperclip-5.2.0 lib/paperclip/tempfile.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/paperclip-5.1.0/lib/paperclip/tempfile.rb
paperclip-5.1.0 lib/paperclip/tempfile.rb
paperclip-5.0.0 lib/paperclip/tempfile.rb
paperclip-4.3.7 lib/paperclip/tempfile.rb
paperclip_jk-5.0.0.beta2 lib/paperclip/tempfile.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/paperclip-4.3.6/lib/paperclip/tempfile.rb
paperclip-5.0.0.beta2 lib/paperclip/tempfile.rb
paperclip-5.0.0.beta1 lib/paperclip/tempfile.rb
paperclip-4.3.6 lib/paperclip/tempfile.rb
paperclip-4.3.5 lib/paperclip/tempfile.rb
paperclip-4.3.4 lib/paperclip/tempfile.rb
paperclip-4.3.3 lib/paperclip/tempfile.rb
paperclip-4.3.2 lib/paperclip/tempfile.rb