mirror of
https://github.com/kemko/paperclip.git
synced 2026-01-01 16:05:40 +03:00
move tempfile to own sourcefile
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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
20
lib/paperclip/tempfile.rb
Normal 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
|
||||
Reference in New Issue
Block a user