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
701abb01
Commit
701abb01
authored
Jan 03, 2009
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If spawn is installed, paperclip will take advantage of it.
parent
84f0d614
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
10 deletions
+66
-10
lib/paperclip/attachment.rb
+30
-10
test/attachment_test.rb
+36
-0
No files found.
lib/paperclip/attachment.rb
View file @
701abb01
...
...
@@ -36,6 +36,7 @@ module Paperclip
@storage
=
options
[
:storage
]
@whiny
=
options
[
:whiny_thumbnails
]
@convert_options
=
options
[
:convert_options
]
||
{}
@background
=
options
[
:background
].
nil?
?
instance
.
respond_to?
(:
spawn
)
:
options
[
:background
]
@processors
=
options
[
:processors
]
||
[
:thumbnail
]
@options
=
options
@queued_for_delete
=
[]
...
...
@@ -254,15 +255,15 @@ module Paperclip
private
def
logger
def
logger
#:nodoc:
instance
.
logger
end
def
log
message
def
log
message
#:nodoc:
logger
.
info
(
"[paperclip]
#{
message
}
"
)
if
logging?
end
def
logging?
def
logging?
#:nodoc:
Paperclip
.
options
[
:log
]
end
...
...
@@ -283,7 +284,7 @@ module Paperclip
@validation_errors
end
def
normalize_style_definition
def
normalize_style_definition
#:nodoc:
@styles
.
each
do
|
name
,
args
|
unless
args
.
is_a?
Hash
dimensions
,
format
=
[
args
,
nil
].
flatten
[
0
..
1
]
...
...
@@ -305,7 +306,7 @@ module Paperclip
end
end
def
initialize_storage
def
initialize_storage
#:nodoc:
@storage_module
=
Paperclip
::
Storage
.
const_get
(
@storage
.
to_s
.
capitalize
)
self
.
extend
(
@storage_module
)
end
...
...
@@ -321,8 +322,19 @@ module Paperclip
def
post_process
#:nodoc:
return
if
@queued_for_write
[
:original
].
nil?
return
if
callback
(
:before_post_process
)
==
false
return
if
callback
(
:"before_
#{
name
}
_post_process"
)
==
false
background
do
return
if
fire_events
(
:before
)
post_process_styles
return
if
fire_events
(
:after
)
end
end
def
fire_events
(
which
)
return
true
if
callback
(
:"
#{
which
}
_post_process"
)
==
false
return
true
if
callback
(
:"
#{
which
}
_
#{
name
}
_post_process"
)
==
false
end
def
post_process_styles
log
(
"Post-processing
#{
name
}
"
)
@styles
.
each
do
|
name
,
args
|
begin
...
...
@@ -336,11 +348,19 @@ module Paperclip
(
@errors
[
:processing
]
||=
[])
<<
e
.
message
if
@whiny
end
end
callback
(
:"after_
#{
name
}
_post_process"
)
callback
(
:after_post_process
)
end
def
callback
which
# When processing, if the spawn plugin is installed, processing can be done in
# a background fork or thread if desired.
def
background
(
&
blk
)
if
instance
.
respond_to?
(
:spawn
)
&&
@background
instance
.
spawn
(
&
blk
)
else
blk
.
call
end
end
def
callback
which
#:nodoc:
instance
.
run_callbacks
(
which
,
@queued_for_write
){
|
result
,
obj
|
result
==
false
}
end
...
...
test/attachment_test.rb
View file @
701abb01
...
...
@@ -210,6 +210,42 @@ class AttachmentTest < Test::Unit::TestCase
end
end
context
"When spawn is not defined on the instance"
do
setup
do
rebuild_model
:styles
=>
{
:foo
=>
true
}
@dummy
=
Dummy
.
new
@file
=
StringIO
.
new
(
"12345"
)
end
should
"not call spawn on the instance when assigned a file"
do
@dummy
.
expects
(
:spawn
).
times
(
0
)
@dummy
.
avatar
.
expects
(
:post_process_styles
)
# This is pretty ugly, but mocha expectations make the object
# respond_to? things it wouldn't have. Gotta get around it.
class
<<
@dummy
def
respond_to_with_spawn?
(
method
)
(
method
==
:spawn
)
?
false
:
respond_to_without_spawn?
(
method
)
end
alias_method_chain
:respond_to?
,
:spawn
end
@dummy
.
avatar
=
@file
end
end
context
"When spawn is defined on the instance"
do
setup
do
Dummy
.
any_instance
.
stubs
(
:spawn
)
rebuild_model
:styles
=>
{
:foo
=>
true
}
@dummy
=
Dummy
.
new
@file
=
StringIO
.
new
(
"12345"
)
end
should
"not call spawn on the instance when assigned a file"
do
@dummy
.
expects
(
:spawn
)
@dummy
.
avatar
=
@file
end
end
context
"An attachment with no processors defined"
do
setup
do
rebuild_model
:processors
=>
[],
:styles
=>
{
:something
=>
1
}
...
...
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