thoughtbot-paperclip 2.2.7 → 2.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/paperclip.rb +1 -1
- data/lib/paperclip/attachment.rb +2 -16
- data/lib/paperclip/storage.rb +4 -9
- data/test/attachment_test.rb +6 -6
- data/test/paperclip_test.rb +0 -4
- metadata +5 -2
data/lib/paperclip.rb
CHANGED
data/lib/paperclip/attachment.rb
CHANGED
@@ -49,8 +49,6 @@ module Paperclip
|
|
49
49
|
|
50
50
|
normalize_style_definition
|
51
51
|
initialize_storage
|
52
|
-
|
53
|
-
log("Paperclip attachment #{name} on #{instance.class} initialized.")
|
54
52
|
end
|
55
53
|
|
56
54
|
# What gets called when you call instance.attachment = File. It clears
|
@@ -62,9 +60,6 @@ module Paperclip
|
|
62
60
|
# If the file that is assigned is not valid, the processing (i.e.
|
63
61
|
# thumbnailing, etc) will NOT be run.
|
64
62
|
def assign uploaded_file
|
65
|
-
# This is because of changes in Rails 2.3 that cause blank fields to send nil
|
66
|
-
return nil if uploaded_file.nil?
|
67
|
-
|
68
63
|
%w(file_name).each do |field|
|
69
64
|
unless @instance.class.column_names.include?("#{name}_#{field}")
|
70
65
|
raise PaperclipError.new("#{@instance.class} model does not have required column '#{name}_#{field}'")
|
@@ -77,16 +72,12 @@ module Paperclip
|
|
77
72
|
end
|
78
73
|
|
79
74
|
return nil unless valid_assignment?(uploaded_file)
|
80
|
-
log("Assigning #{uploaded_file.inspect} to #{name}")
|
81
75
|
|
82
76
|
uploaded_file.binmode if uploaded_file.respond_to? :binmode
|
83
|
-
|
84
|
-
@errors = {}
|
85
|
-
@validation_errors = nil
|
77
|
+
self.clear
|
86
78
|
|
87
79
|
return nil if uploaded_file.nil?
|
88
80
|
|
89
|
-
log("Writing attributes for #{name}")
|
90
81
|
@queued_for_write[:original] = uploaded_file.to_tempfile
|
91
82
|
instance_write(:file_name, uploaded_file.original_filename.strip.gsub(/[^\w\d\.\-]+/, '_'))
|
92
83
|
instance_write(:content_type, uploaded_file.content_type.to_s.strip)
|
@@ -149,13 +140,11 @@ module Paperclip
|
|
149
140
|
# the instance's errors and returns false, cancelling the save.
|
150
141
|
def save
|
151
142
|
if valid?
|
152
|
-
log("Saving files for #{name}")
|
153
143
|
flush_deletes
|
154
144
|
flush_writes
|
155
145
|
@dirty = false
|
156
146
|
true
|
157
147
|
else
|
158
|
-
log("Errors on #{name}. Not saving.")
|
159
148
|
flush_errors
|
160
149
|
false
|
161
150
|
end
|
@@ -293,7 +282,7 @@ module Paperclip
|
|
293
282
|
end
|
294
283
|
|
295
284
|
def valid_assignment? file #:nodoc:
|
296
|
-
file.respond_to?(:original_filename) && file.respond_to?(:content_type)
|
285
|
+
file.nil? || (file.respond_to?(:original_filename) && file.respond_to?(:content_type))
|
297
286
|
end
|
298
287
|
|
299
288
|
def validate #:nodoc:
|
@@ -370,12 +359,10 @@ module Paperclip
|
|
370
359
|
end
|
371
360
|
|
372
361
|
def post_process_styles
|
373
|
-
log("Post-processing #{name}")
|
374
362
|
@styles.each do |name, args|
|
375
363
|
begin
|
376
364
|
raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank?
|
377
365
|
@queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor|
|
378
|
-
log("Processing #{name} #{file} in the #{processor} processor.")
|
379
366
|
Paperclip.processor(processor).make(file, args, self)
|
380
367
|
end
|
381
368
|
rescue PaperclipError => e
|
@@ -397,7 +384,6 @@ module Paperclip
|
|
397
384
|
|
398
385
|
def queue_existing_for_delete #:nodoc:
|
399
386
|
return unless file?
|
400
|
-
log("Queueing the existing files for #{name} for deletion.")
|
401
387
|
@queued_for_delete += [:original, *@styles.keys].uniq.map do |style|
|
402
388
|
path(style) if exists?(style)
|
403
389
|
end.compact
|
data/lib/paperclip/storage.rb
CHANGED
@@ -36,11 +36,10 @@ module Paperclip
|
|
36
36
|
alias_method :to_io, :to_file
|
37
37
|
|
38
38
|
def flush_writes #:nodoc:
|
39
|
-
logger.info("[paperclip] Writing files for #{name}")
|
40
39
|
@queued_for_write.each do |style, file|
|
41
40
|
file.close
|
42
41
|
FileUtils.mkdir_p(File.dirname(path(style)))
|
43
|
-
logger.info("[paperclip]
|
42
|
+
logger.info("[paperclip] saving #{path(style)}")
|
44
43
|
FileUtils.mv(file.path, path(style))
|
45
44
|
FileUtils.chmod(0644, path(style))
|
46
45
|
end
|
@@ -48,10 +47,9 @@ module Paperclip
|
|
48
47
|
end
|
49
48
|
|
50
49
|
def flush_deletes #:nodoc:
|
51
|
-
logger.info("[paperclip] Deleting files for #{name}")
|
52
50
|
@queued_for_delete.each do |path|
|
53
51
|
begin
|
54
|
-
logger.info("[paperclip]
|
52
|
+
logger.info("[paperclip] deleting #{path}")
|
55
53
|
FileUtils.rm(path) if File.exist?(path)
|
56
54
|
rescue Errno::ENOENT => e
|
57
55
|
# ignore file-not-found, let everything else pass
|
@@ -151,7 +149,6 @@ module Paperclip
|
|
151
149
|
base.class.interpolations[:s3_domain_url] = lambda do |attachment, style|
|
152
150
|
"#{attachment.s3_protocol}://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}"
|
153
151
|
end
|
154
|
-
ActiveRecord::Base.logger.info("[paperclip] S3 Storage Initalized.")
|
155
152
|
end
|
156
153
|
|
157
154
|
def s3
|
@@ -193,10 +190,9 @@ module Paperclip
|
|
193
190
|
alias_method :to_io, :to_file
|
194
191
|
|
195
192
|
def flush_writes #:nodoc:
|
196
|
-
logger.info("[paperclip] Writing files for #{name}")
|
197
193
|
@queued_for_write.each do |style, file|
|
198
194
|
begin
|
199
|
-
logger.info("[paperclip]
|
195
|
+
logger.info("[paperclip] saving #{path(style)}")
|
200
196
|
key = s3_bucket.key(path(style))
|
201
197
|
key.data = file
|
202
198
|
key.put(nil, @s3_permissions, {'Content-type' => instance_read(:content_type)}.merge(@s3_headers))
|
@@ -208,10 +204,9 @@ module Paperclip
|
|
208
204
|
end
|
209
205
|
|
210
206
|
def flush_deletes #:nodoc:
|
211
|
-
logger.info("[paperclip] Writing files for #{name}")
|
212
207
|
@queued_for_delete.each do |path|
|
213
208
|
begin
|
214
|
-
logger.info("[paperclip]
|
209
|
+
logger.info("[paperclip] deleting #{path}")
|
215
210
|
if file = s3_bucket.key(path)
|
216
211
|
file.delete
|
217
212
|
end
|
data/test/attachment_test.rb
CHANGED
@@ -599,14 +599,14 @@ class AttachmentTest < Test::Unit::TestCase
|
|
599
599
|
end
|
600
600
|
end
|
601
601
|
|
602
|
-
should "
|
603
|
-
@attachment.expects(:instance_write).with(:file_name, nil)
|
604
|
-
@attachment.expects(:instance_write).with(:content_type, nil)
|
605
|
-
@attachment.expects(:instance_write).with(:file_size, nil)
|
606
|
-
@attachment.expects(:instance_write).with(:updated_at, nil)
|
602
|
+
should "delete the files after assigning nil" do
|
603
|
+
@attachment.expects(:instance_write).with(:file_name, nil)
|
604
|
+
@attachment.expects(:instance_write).with(:content_type, nil)
|
605
|
+
@attachment.expects(:instance_write).with(:file_size, nil)
|
606
|
+
@attachment.expects(:instance_write).with(:updated_at, nil)
|
607
607
|
@attachment.assign nil
|
608
608
|
@attachment.save
|
609
|
-
@existing_names.each{|f| assert File.exists?(f) }
|
609
|
+
@existing_names.each{|f| assert ! File.exists?(f) }
|
610
610
|
end
|
611
611
|
|
612
612
|
should "delete the files when you call #clear and #save" do
|
data/test/paperclip_test.rb
CHANGED
@@ -91,8 +91,6 @@ class PaperclipTest < Test::Unit::TestCase
|
|
91
91
|
end
|
92
92
|
|
93
93
|
should "not assign the avatar on mass-set" do
|
94
|
-
@dummy.logger.expects(:debug)
|
95
|
-
|
96
94
|
@dummy.attributes = { :other => "I'm set!",
|
97
95
|
:avatar => @file }
|
98
96
|
|
@@ -101,8 +99,6 @@ class PaperclipTest < Test::Unit::TestCase
|
|
101
99
|
end
|
102
100
|
|
103
101
|
should "still allow assigment on normal set" do
|
104
|
-
@dummy.logger.expects(:debug).times(0)
|
105
|
-
|
106
102
|
@dummy.other = "I'm set!"
|
107
103
|
@dummy.avatar = @file
|
108
104
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thoughtbot-paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Yurek
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-02 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- test/fixtures/50x50.png
|
86
86
|
- test/fixtures/5k.png
|
87
87
|
- test/fixtures/bad.png
|
88
|
+
- test/fixtures/s3.yml
|
88
89
|
- test/fixtures/text.txt
|
89
90
|
- test/fixtures/twopage.pdf
|
90
91
|
- test/geometry_test.rb
|
@@ -101,6 +102,8 @@ files:
|
|
101
102
|
- test/s3.yml
|
102
103
|
- test/storage_test.rb
|
103
104
|
- test/thumbnail_test.rb
|
105
|
+
- test/tmp
|
106
|
+
- test/tmp/storage.txt
|
104
107
|
- shoulda_macros/paperclip.rb
|
105
108
|
has_rdoc: true
|
106
109
|
homepage: http://www.thoughtbot.com/projects/paperclip
|