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
d8f45ee0
Commit
d8f45ee0
authored
Apr 23, 2010
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backporting the modifications for Rails 3 to Rails 2.3
parent
9b9b944f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
38 deletions
+85
-38
lib/paperclip.rb
+8
-16
lib/paperclip/attachment.rb
+2
-2
lib/paperclip/callback_compatability.rb
+65
-17
test/attachment_test.rb
+5
-0
test/helper.rb
+5
-3
No files found.
lib/paperclip.rb
View file @
d8f45ee0
...
...
@@ -36,6 +36,7 @@ require 'paperclip/storage'
require
'paperclip/interpolations'
require
'paperclip/style'
require
'paperclip/attachment'
require
'paperclip/callback_compatability'
if
defined?
(
Rails
.
root
)
&&
Rails
.
root
Dir
.
glob
(
File
.
join
(
File
.
expand_path
(
Rails
.
root
),
"lib"
,
"paperclip_processors"
,
"*.rb"
)).
each
do
|
processor
|
require
processor
...
...
@@ -111,6 +112,13 @@ module Paperclip
def
included
base
#:nodoc:
base
.
extend
ClassMethods
if
base
.
respond_to?
(
"set_callback"
)
base
.
send
:include
,
Paperclip
::
CallbackCompatability
::
Rails3
elsif
!
base
.
respond_to?
(
"define_callbacks"
)
base
.
send
:include
,
Paperclip
::
CallbackCompatability
::
Rails20
else
base
.
send
:include
,
Paperclip
::
CallbackCompatability
::
Rails21
end
end
def
processor
name
#:nodoc:
...
...
@@ -314,22 +322,6 @@ module Paperclip
def
attachment_definitions
read_inheritable_attribute
(
:attachment_definitions
)
end
private
def
define_paperclip_callbacks
(
*
callbacks
)
define_callbacks
*
[
callbacks
,
{
:terminator
=>
"result == false"
}].
flatten
callbacks
.
each
do
|
callback
|
eval
<<-
end_callbacks
def before_
#{
callback
}
(*args, &blk)
set_callback(:
#{
callback
}
, :before, *args, &blk)
end
def after_
#{
callback
}
(*args, &blk)
set_callback(:
#{
callback
}
, :after, *args, &blk)
end
end_callbacks
end
end
end
module
InstanceMethods
#:nodoc:
...
...
lib/paperclip/attachment.rb
View file @
d8f45ee0
...
...
@@ -280,8 +280,8 @@ module Paperclip
def
post_process
#:nodoc:
return
if
@queued_for_write
[
:original
].
nil?
instance
.
run_callbacks
(
:post_process
)
do
instance
.
run_callbacks
(
:"
#{
name
}
_post_process"
)
do
instance
.
run_
paperclip_
callbacks
(
:post_process
)
do
instance
.
run_
paperclip_
callbacks
(
:"
#{
name
}
_post_process"
)
do
post_process_styles
end
end
...
...
lib/paperclip/callback_compatability.rb
View file @
d8f45ee0
...
...
@@ -2,32 +2,80 @@ module Paperclip
# This module is intended as a compatability shim for the differences in
# callbacks between Rails 2.0 and Rails 2.1.
module
CallbackCompatability
module
Rails20
def
self
.
included
(
base
)
base
.
extend
(
ClassMethods
)
base
.
send
(
:include
,
InstanceMethods
)
base
.
extend
(
Defining
)
base
.
send
(
:include
,
Running
)
puts
"Including Rails 2.0 Compatability"
end
module
ClassMethods
# The implementation of this method is taken from the Rails 1.2.6 source,
# from rails/activerecord/lib/active_record/callbacks.rb, line 192.
def
define_callbacks
(
*
args
)
args
.
each
do
|
method
|
self
.
class_eval
<<-
"end_eval"
def self.
#{
method
}
(*callbacks, &block)
callbacks << block if block_given?
write_inheritable_array(
#{
method
.
to_sym
.
inspect
}
, callbacks)
module
Defining
def
define_paperclip_callbacks
(
*
args
)
end
end_eval
end
module
Running
def
run_paperclip_callbacks
(
callback
,
opts
=
nil
,
&
blk
)
end
end
end
module
Rails21
def
self
.
included
(
base
)
base
.
extend
(
Defining
)
base
.
send
(
:include
,
Running
)
end
module
Defining
def
define_paperclip_callbacks
(
*
args
)
args
.
each
do
|
callback
|
define_callbacks
(
"before_
#{
callback
}
"
)
define_callbacks
(
"after_
#{
callback
}
"
)
end
end
end
module
Running
def
run_paperclip_callbacks
(
callback
,
opts
=
nil
,
&
blk
)
# The overall structure of this isn't ideal since after callbacks run even if
# befores return false. But this is how rails 3's callbacks work, unfortunately.
if
run_callbacks
(
:"before_
#{
callback
}
"
){
|
result
,
object
|
result
==
false
}
!=
false
blk
.
call
end
run_callbacks
(
:"after_
#{
callback
}
"
){
|
result
,
object
|
result
==
false
}
end
end
end
module
Rails3
def
self
.
included
(
base
)
base
.
extend
(
Defining
)
base
.
send
(
:include
,
Running
)
end
module
InstanceMethods
# The callbacks in < 2.1 don't worry about the extra options or the
# block, so just run what we have available.
def
run_callbacks
(
meth
,
opts
=
nil
,
&
blk
)
callback
(
meth
)
module
Defining
def
define_paperclip_callbacks
(
*
callbacks
)
define_callbacks
*
[
callbacks
,
{
:terminator
=>
"result == false"
}].
flatten
callbacks
.
each
do
|
callback
|
eval
<<-
end_callbacks
def before_
#{
callback
}
(*args, &blk)
set_callback(:
#{
callback
}
, :before, *args, &blk)
end
def after_
#{
callback
}
(*args, &blk)
set_callback(:
#{
callback
}
, :after, *args, &blk)
end
end_callbacks
end
end
end
module
Running
def
run_paperclip_callbacks
(
callback
,
opts
=
nil
,
&
block
)
run_callbacks
(
callback
,
opts
,
&
block
)
end
end
end
end
end
test/attachment_test.rb
View file @
d8f45ee0
...
...
@@ -399,12 +399,17 @@ class AttachmentTest < Test::Unit::TestCase
end
should
"cancel the processing if a before_post_process returns false"
do
begin
$DEBUG
=
true
@dummy
.
expects
(
:do_before_avatar
).
never
@dummy
.
expects
(
:do_after_avatar
).
never
@dummy
.
expects
(
:do_before_all
).
with
().
returns
(
false
)
@dummy
.
expects
(
:do_after_all
)
Paperclip
::
Thumbnail
.
expects
(
:make
).
never
@dummy
.
avatar
=
@file
ensure
$DEBUG
=
false
end
end
should
"cancel the processing if a before_avatar_post_process returns false"
do
...
...
test/helper.rb
View file @
d8f45ee0
...
...
@@ -8,8 +8,9 @@ require 'mocha'
gem
'sqlite3-ruby'
require
'active_record'
require
'active_support'
require
'activerecord'
require
'activesupport'
require
'actionpack'
begin
require
'ruby-debug'
rescue
LoadError
...
...
@@ -94,8 +95,9 @@ class FakeModel
@errors
||=
[]
end
def
run_callbacks
name
,
*
args
def
run_
paperclip_
callbacks
name
,
*
args
end
end
def
attachment
options
...
...
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