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
632ea47a
Commit
632ea47a
authored
Sep 10, 2012
by
Alexander Ivanov
Committed by
Jon Yurek
Nov 01, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow to use lambdas in only_process option
parent
75a8bd20
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
lib/paperclip/attachment.rb
+6
-3
test/attachment_test.rb
+19
-0
No files found.
lib/paperclip/attachment.rb
View file @
632ea47a
...
@@ -90,8 +90,11 @@ module Paperclip
...
@@ -90,8 +90,11 @@ module Paperclip
ensure_required_accessors!
ensure_required_accessors!
file
=
Paperclip
.
io_adapters
.
for
(
uploaded_file
)
file
=
Paperclip
.
io_adapters
.
for
(
uploaded_file
)
@options
[
:only_process
].
map!
(
&
:to_sym
)
only_process
=
@options
[
:only_process
].
dup
self
.
clear
(
*
@options
[
:only_process
])
only_process
=
only_process
.
call
(
self
)
if
only_process
.
respond_to?
(
:call
)
only_process
.
map!
(
&
:to_sym
)
self
.
clear
(
*
only_process
)
return
nil
if
file
.
nil?
return
nil
if
file
.
nil?
@queued_for_write
[
:original
]
=
file
@queued_for_write
[
:original
]
=
file
...
@@ -104,7 +107,7 @@ module Paperclip
...
@@ -104,7 +107,7 @@ module Paperclip
@dirty
=
true
@dirty
=
true
post_process
(
*
@options
[
:only_process
]
)
if
post_processing
post_process
(
*
only_process
)
if
post_processing
# Reset the file size if the original file was reprocessed.
# Reset the file size if the original file was reprocessed.
instance_write
(
:file_size
,
@queued_for_write
[
:original
].
size
)
instance_write
(
:file_size
,
@queued_for_write
[
:original
].
size
)
...
...
test/attachment_test.rb
View file @
632ea47a
...
@@ -385,6 +385,25 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -385,6 +385,25 @@ class AttachmentTest < Test::Unit::TestCase
end
end
end
end
context
"An attachment with :only_process that is a proc"
do
setup
do
rebuild_model
:styles
=>
{
:thumb
=>
"100x100"
,
:large
=>
"400x400"
},
:only_process
=>
lambda
{
|
attachment
|
[
:thumb
]
}
@file
=
StringIO
.
new
(
"..."
)
@attachment
=
Dummy
.
new
.
avatar
end
should
"only process the provided style"
do
@attachment
.
expects
(
:post_process
).
with
(
:thumb
)
@attachment
.
expects
(
:post_process
).
with
(
:large
).
never
@attachment
.
assign
(
@file
)
end
end
context
"An attachment with :convert_options that is a proc"
do
context
"An attachment with :convert_options that is a proc"
do
setup
do
setup
do
rebuild_model
:styles
=>
{
rebuild_model
:styles
=>
{
...
...
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