Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
1fef4c30
Commit
1fef4c30
authored
Oct 05, 2010
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only use Tempfile subclass in 1.8.6 and below. Fixes #278.
parent
05498d27
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
8 deletions
+21
-8
lib/paperclip/iostream.rb
+1
-1
lib/paperclip/processor.rb
+13
-4
lib/paperclip/storage/s3.rb
+4
-1
lib/paperclip/thumbnail.rb
+1
-1
test/thumbnail_test.rb
+2
-1
No files found.
lib/paperclip/iostream.rb
View file @
1fef4c30
...
...
@@ -5,7 +5,7 @@ module IOStream
# Returns a Tempfile containing the contents of the readable object.
def
to_tempfile
name
=
respond_to?
(
:original_filename
)
?
original_filename
:
(
respond_to?
(
:path
)
?
path
:
"stream"
)
tempfile
=
Paperclip
::
Tempfile
.
new
(
"stream"
+
File
.
extname
(
name
)
)
tempfile
=
Paperclip
::
Tempfile
.
new
(
[
"stream"
,
File
.
extname
(
name
)]
)
tempfile
.
binmode
self
.
stream_to
(
tempfile
)
end
...
...
lib/paperclip/processor.rb
View file @
1fef4c30
...
...
@@ -40,10 +40,19 @@ module Paperclip
# 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
)
# This is Ruby 1.8.7's implementation.
if
RUBY_VERSION
<=
"1.8.6"
def
make_tmpname
(
basename
,
n
)
case
basename
when
Array
prefix
,
suffix
=
*
basename
else
prefix
,
suffix
=
basename
,
''
end
t
=
time
.
now
.
strftime
(
"%y%m%d"
)
path
=
"
#{
prefix
}#{
t
}
-
#{
$$
}
-
#{
rand
(
0x100000000
).
to_s
(
36
)
}
-
#{
n
}#{
suffix
}
"
end
end
end
end
lib/paperclip/storage/s3.rb
View file @
1fef4c30
...
...
@@ -127,7 +127,10 @@ module Paperclip
# style, in the format most representative of the current storage.
def
to_file
style
=
default_style
return
@queued_for_write
[
style
]
if
@queued_for_write
[
style
]
file
=
Tempfile
.
new
(
path
(
style
))
filename
=
path
(
style
).
split
(
"."
)
extname
=
File
.
extname
(
filename
)
basename
=
File
.
basename
(
filename
,
extname
)
file
=
Tempfile
.
new
(
basename
,
extname
)
file
.
write
(
AWS
::
S3
::
S3Object
.
value
(
path
(
style
),
bucket_name
))
file
.
rewind
return
file
...
...
lib/paperclip/thumbnail.rb
View file @
1fef4c30
...
...
@@ -45,7 +45,7 @@ module Paperclip
# that contains the new image.
def
make
src
=
@file
dst
=
Tempfile
.
new
([
@basename
,
@format
].
compact
.
join
(
"."
)
)
dst
=
Tempfile
.
new
([
@basename
,
@format
?
".
#{
@format
}
"
:
''
]
)
dst
.
binmode
begin
...
...
test/thumbnail_test.rb
View file @
1fef4c30
...
...
@@ -4,10 +4,11 @@ class ThumbnailTest < Test::Unit::TestCase
context
"A Paperclip Tempfile"
do
setup
do
@tempfile
=
Paperclip
::
Tempfile
.
new
(
"file.jpg"
)
@tempfile
=
Paperclip
::
Tempfile
.
new
(
[
"file"
,
".jpg"
]
)
end
should
"have its path contain a real extension"
do
p
@tempfile
.
path
assert_equal
".jpg"
,
File
.
extname
(
@tempfile
.
path
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment