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
e705b737
Commit
e705b737
authored
Apr 24, 2012
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't delete all the existing styles if we reprocess
parent
a596c01b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
7 deletions
+37
-7
lib/paperclip/attachment.rb
+16
-6
lib/paperclip/instance_methods.rb
+1
-1
test/attachment_test.rb
+20
-0
No files found.
lib/paperclip/attachment.rb
View file @
e705b737
...
...
@@ -90,7 +90,7 @@ module Paperclip
ensure_required_accessors!
file
=
Paperclip
.
io_adapters
.
for
(
uploaded_file
)
self
.
clear
self
.
clear
(
*
@options
[
:only_process
])
return
nil
if
file
.
nil?
@queued_for_write
[
:original
]
=
file
...
...
@@ -202,10 +202,14 @@ module Paperclip
# Clears out the attachment. Has the same effect as previously assigning
# nil to the attachment. Does NOT save. If you wish to clear AND save,
# use #destroy.
def
clear
queue_existing_for_delete
@queued_for_write
=
{}
@errors
=
{}
def
clear
(
*
styles_to_clear
)
if
styles_to_clear
.
any?
queue_some_for_delete
(
*
styles_to_clear
)
else
queue_all_for_delete
@queued_for_write
=
{}
@errors
=
{}
end
end
# Destroys the attachment. Has the same effect as previously assigning
...
...
@@ -406,7 +410,13 @@ module Paperclip
interpolator
.
interpolate
(
pattern
,
self
,
style_name
)
end
def
queue_existing_for_delete
#:nodoc:
def
queue_some_for_delete
(
*
styles
)
@queued_for_delete
+=
styles
.
uniq
.
map
do
|
style
|
path
(
style
)
if
exists?
(
style
)
end
.
compact
end
def
queue_all_for_delete
#:nodoc:
return
if
@options
[
:preserve_files
]
||
!
file?
@queued_for_delete
+=
[
:original
,
*
styles
.
keys
].
uniq
.
map
do
|
style
|
path
(
style
)
if
exists?
(
style
)
...
...
lib/paperclip/instance_methods.rb
View file @
e705b737
...
...
@@ -28,7 +28,7 @@ module Paperclip
def
prepare_for_destroy
Paperclip
.
log
(
"Scheduling attachments for deletion."
)
each_attachment
do
|
name
,
attachment
|
attachment
.
send
(
:queue_
existing
_for_delete
)
attachment
.
send
(
:queue_
all
_for_delete
)
end
end
end
...
...
test/attachment_test.rb
View file @
e705b737
...
...
@@ -19,6 +19,26 @@ class AttachmentTest < Test::Unit::TestCase
file
.
close
end
should
"not delete styles that don't get reprocessed"
do
file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"50x50.png"
),
'rb'
)
rebuild_class
:styles
=>
{
:small
=>
'100x>'
,
:large
=>
'500x>'
,
:original
=>
'42x42#'
}
dummy
=
Dummy
.
new
dummy
.
avatar
=
file
dummy
.
save
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:small
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:large
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:original
))
dummy
.
avatar
.
reprocess!
(
:small
)
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:small
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:large
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:original
))
end
should
"handle a boolean second argument to #url"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:url_generator
=>
mock_url_generator_builder
)
...
...
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