paperclip 2.3.4 → 2.3.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of paperclip might be problematic. Click here for more details.
- data/lib/paperclip.rbc +85 -0
- data/lib/paperclip/attachment.rb +2 -1
- data/lib/paperclip/attachment.rbc +1715 -0
- data/lib/paperclip/configuration.rbc +1009 -0
- data/lib/paperclip/iostream.rb +9 -23
- data/lib/paperclip/processor.rb +1 -1
- data/lib/paperclip/storage/s3.rb +2 -2
- data/lib/paperclip/upfile.rb +3 -1
- data/lib/paperclip/version.rb +1 -1
- data/test/iostream_test.rb +5 -12
- data/test/storage_test.rb +5 -0
- data/test/thumbnail_test.rb +0 -1
- data/test/upfile_test.rb +17 -0
- metadata +7 -4
data/lib/paperclip/iostream.rb
CHANGED
@@ -1,29 +1,27 @@
|
|
1
1
|
# Provides method that can be included on File-type objects (IO, StringIO, Tempfile, etc) to allow stream copying
|
2
2
|
# and Tempfile conversion.
|
3
3
|
module IOStream
|
4
|
-
|
5
4
|
# Returns a Tempfile containing the contents of the readable object.
|
6
|
-
def to_tempfile
|
7
|
-
|
5
|
+
def to_tempfile(object)
|
6
|
+
return object.to_tempfile if object.respond_to?(:to_tempfile)
|
7
|
+
name = object.respond_to?(:original_filename) ? object.original_filename : (object.respond_to?(:path) ? object.path : "stream")
|
8
8
|
tempfile = Paperclip::Tempfile.new(["stream", File.extname(name)])
|
9
9
|
tempfile.binmode
|
10
|
-
|
10
|
+
stream_to(object, tempfile)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Copies one read-able object from one place to another in blocks, obviating the need to load
|
14
|
-
# the whole thing into memory. Defaults to 8k blocks.
|
15
|
-
#
|
16
|
-
|
17
|
-
# and returns the IO or Tempfile as passed in if one is sent as the destination.
|
18
|
-
def stream_to path_or_file, in_blocks_of = 8192
|
14
|
+
# the whole thing into memory. Defaults to 8k blocks. Returns a File if a String is passed
|
15
|
+
# in as the destination and returns the IO or Tempfile as passed in if one is sent as the destination.
|
16
|
+
def stream_to object, path_or_file, in_blocks_of = 8192
|
19
17
|
dstio = case path_or_file
|
20
18
|
when String then File.new(path_or_file, "wb+")
|
21
19
|
when IO then path_or_file
|
22
20
|
when Tempfile then path_or_file
|
23
21
|
end
|
24
22
|
buffer = ""
|
25
|
-
|
26
|
-
while
|
23
|
+
object.rewind
|
24
|
+
while object.read(in_blocks_of, buffer) do
|
27
25
|
dstio.write(buffer)
|
28
26
|
end
|
29
27
|
dstio.rewind
|
@@ -31,18 +29,6 @@ module IOStream
|
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
|
-
class IO #:nodoc:
|
35
|
-
include IOStream
|
36
|
-
end
|
37
|
-
|
38
|
-
%w( Tempfile StringIO ).each do |klass|
|
39
|
-
if Object.const_defined? klass
|
40
|
-
Object.const_get(klass).class_eval do
|
41
|
-
include IOStream
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
32
|
# Corrects a bug in Windows when asking for Tempfile size.
|
47
33
|
if defined? Tempfile
|
48
34
|
class Tempfile
|
data/lib/paperclip/processor.rb
CHANGED
data/lib/paperclip/storage/s3.rb
CHANGED
@@ -127,10 +127,10 @@ module Paperclip
|
|
127
127
|
# style, in the format most representative of the current storage.
|
128
128
|
def to_file style = default_style
|
129
129
|
return @queued_for_write[style] if @queued_for_write[style]
|
130
|
-
filename = path(style)
|
130
|
+
filename = path(style)
|
131
131
|
extname = File.extname(filename)
|
132
132
|
basename = File.basename(filename, extname)
|
133
|
-
file = Tempfile.new(basename, extname)
|
133
|
+
file = Tempfile.new([basename, extname])
|
134
134
|
file.write(AWS::S3::S3Object.value(path(style), bucket_name))
|
135
135
|
file.rewind
|
136
136
|
return file
|
data/lib/paperclip/upfile.rb
CHANGED
data/lib/paperclip/version.rb
CHANGED
data/test/iostream_test.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
require 'test/helper'
|
2
2
|
|
3
3
|
class IOStreamTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
should "be included in IO, File, Tempfile, and StringIO" do
|
6
|
-
[IO, File, Tempfile, StringIO].each do |klass|
|
7
|
-
assert klass.included_modules.include?(IOStream), "Not in #{klass}"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
4
|
+
include IOStream
|
12
5
|
context "A file" do
|
13
6
|
setup do
|
14
7
|
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
|
@@ -21,7 +14,7 @@ class IOStreamTest < Test::Unit::TestCase
|
|
21
14
|
context "and given a String" do
|
22
15
|
setup do
|
23
16
|
FileUtils.mkdir_p(File.join(ROOT, 'tmp'))
|
24
|
-
assert @result = @file
|
17
|
+
assert @result = stream_to(@file, File.join(ROOT, 'tmp', 'iostream.string.test'))
|
25
18
|
end
|
26
19
|
|
27
20
|
should "return a File" do
|
@@ -38,7 +31,7 @@ class IOStreamTest < Test::Unit::TestCase
|
|
38
31
|
setup do
|
39
32
|
tempfile = Tempfile.new('iostream.test')
|
40
33
|
tempfile.binmode
|
41
|
-
assert @result = @file
|
34
|
+
assert @result = stream_to(@file, tempfile)
|
42
35
|
end
|
43
36
|
|
44
37
|
should "return a Tempfile" do
|
@@ -53,9 +46,9 @@ class IOStreamTest < Test::Unit::TestCase
|
|
53
46
|
|
54
47
|
end
|
55
48
|
|
56
|
-
context "that is
|
49
|
+
context "that is converted #to_tempfile" do
|
57
50
|
setup do
|
58
|
-
assert @tempfile = @file
|
51
|
+
assert @tempfile = to_tempfile(@file)
|
59
52
|
end
|
60
53
|
|
61
54
|
should "convert it to a Paperclip Tempfile" do
|
data/test/storage_test.rb
CHANGED
@@ -351,6 +351,11 @@ class StorageTest < Test::Unit::TestCase
|
|
351
351
|
should "be on S3" do
|
352
352
|
assert true
|
353
353
|
end
|
354
|
+
|
355
|
+
should "generate a tempfile with the right name" do
|
356
|
+
file = @dummy.avatar.to_file
|
357
|
+
assert_match /^original.*\.png$/, File.basename(file.path)
|
358
|
+
end
|
354
359
|
end
|
355
360
|
end
|
356
361
|
end
|
data/test/thumbnail_test.rb
CHANGED
data/test/upfile_test.rb
CHANGED
@@ -33,4 +33,21 @@ class UpfileTest < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
assert_equal 'text/plain', file.content_type
|
35
35
|
end
|
36
|
+
|
37
|
+
should "return a MD5 fingerprint of the file" do
|
38
|
+
file = StringIO.new("1234567890")
|
39
|
+
class << file
|
40
|
+
include Paperclip::Upfile
|
41
|
+
end
|
42
|
+
assert_equal "e807f1fcf82d132f9bb018ca6738a19f", file.fingerprint
|
43
|
+
end
|
44
|
+
|
45
|
+
should "still be readable after the file fingerprints itself" do
|
46
|
+
file = StringIO.new("1234567890")
|
47
|
+
class << file
|
48
|
+
include Paperclip::Upfile
|
49
|
+
end
|
50
|
+
file.fingerprint
|
51
|
+
assert_equal "1234567890", file.read
|
52
|
+
end
|
36
53
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 2.3.
|
9
|
+
- 5
|
10
|
+
version: 2.3.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jon Yurek
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-26 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -119,8 +119,10 @@ files:
|
|
119
119
|
- lib/generators/paperclip/templates/paperclip_migration.rb.erb
|
120
120
|
- lib/generators/paperclip/USAGE
|
121
121
|
- lib/paperclip/attachment.rb
|
122
|
+
- lib/paperclip/attachment.rbc
|
122
123
|
- lib/paperclip/callback_compatability.rb
|
123
124
|
- lib/paperclip/command_line.rb
|
125
|
+
- lib/paperclip/configuration.rbc
|
124
126
|
- lib/paperclip/geometry.rb
|
125
127
|
- lib/paperclip/interpolations.rb
|
126
128
|
- lib/paperclip/iostream.rb
|
@@ -139,6 +141,7 @@ files:
|
|
139
141
|
- lib/paperclip/upfile.rb
|
140
142
|
- lib/paperclip/version.rb
|
141
143
|
- lib/paperclip.rb
|
144
|
+
- lib/paperclip.rbc
|
142
145
|
- lib/tasks/paperclip.rake
|
143
146
|
- test/attachment_test.rb
|
144
147
|
- test/command_line_test.rb
|