move tempfile to own sourcefile

This commit is contained in:
Vasily Fedoseyev
2024-04-06 16:33:00 +03:00
parent e855646d8b
commit 6934695bba
3 changed files with 21 additions and 13 deletions

View File

@@ -32,6 +32,7 @@ require 'paperclip/upfile'
require 'paperclip/iostream'
require 'paperclip/geometry'
require 'paperclip/processor'
require 'paperclip/tempfile'
require 'paperclip/thumbnail'
require 'paperclip/recursive_thumbnail'
require 'paperclip/storage'

View File

@@ -33,17 +33,4 @@ module Paperclip
new(file, options, attachment).make
end
end
# 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
class Tempfile < ::Tempfile
# Replaces Tempfile's +make_tmpname+ with one that honors file extensions.
def make_tmpname(basename, n)
extension = File.extname(basename)
sprintf("%s,%d,%d%s", File.basename(basename, extension), $$, n.to_i, extension)
end
end
end

20
lib/paperclip/tempfile.rb Normal file
View File

@@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'English'
module Paperclip
# 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
class Tempfile < ::Tempfile
# это похоже актуально только для java (не проверял, в mri 3.2 точно не вызывается)
# Replaces Tempfile's +make_tmpname+ with one that honors file extensions.
def make_tmpname(basename, n)
extension = File.extname(basename)
sprintf("%s,%d,%d%s", File.basename(basename, extension), $PROCESS_ID, n.to_i, extension)
end
end
end