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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
40 deletions
+87
-40
lib/paperclip.rb
+8
-16
lib/paperclip/attachment.rb
+2
-2
lib/paperclip/callback_compatability.rb
+67
-19
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'
...
@@ -36,6 +36,7 @@ require 'paperclip/storage'
require
'paperclip/interpolations'
require
'paperclip/interpolations'
require
'paperclip/style'
require
'paperclip/style'
require
'paperclip/attachment'
require
'paperclip/attachment'
require
'paperclip/callback_compatability'
if
defined?
(
Rails
.
root
)
&&
Rails
.
root
if
defined?
(
Rails
.
root
)
&&
Rails
.
root
Dir
.
glob
(
File
.
join
(
File
.
expand_path
(
Rails
.
root
),
"lib"
,
"paperclip_processors"
,
"*.rb"
)).
each
do
|
processor
|
Dir
.
glob
(
File
.
join
(
File
.
expand_path
(
Rails
.
root
),
"lib"
,
"paperclip_processors"
,
"*.rb"
)).
each
do
|
processor
|
require
processor
require
processor
...
@@ -111,6 +112,13 @@ module Paperclip
...
@@ -111,6 +112,13 @@ module Paperclip
def
included
base
#:nodoc:
def
included
base
#:nodoc:
base
.
extend
ClassMethods
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
end
def
processor
name
#:nodoc:
def
processor
name
#:nodoc:
...
@@ -314,22 +322,6 @@ module Paperclip
...
@@ -314,22 +322,6 @@ module Paperclip
def
attachment_definitions
def
attachment_definitions
read_inheritable_attribute
(
:attachment_definitions
)
read_inheritable_attribute
(
:attachment_definitions
)
end
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
end
module
InstanceMethods
#:nodoc:
module
InstanceMethods
#:nodoc:
...
...
lib/paperclip/attachment.rb
View file @
d8f45ee0
...
@@ -280,8 +280,8 @@ module Paperclip
...
@@ -280,8 +280,8 @@ module Paperclip
def
post_process
#:nodoc:
def
post_process
#:nodoc:
return
if
@queued_for_write
[
:original
].
nil?
return
if
@queued_for_write
[
:original
].
nil?
instance
.
run_callbacks
(
:post_process
)
do
instance
.
run_
paperclip_
callbacks
(
:post_process
)
do
instance
.
run_callbacks
(
:"
#{
name
}
_post_process"
)
do
instance
.
run_
paperclip_
callbacks
(
:"
#{
name
}
_post_process"
)
do
post_process_styles
post_process_styles
end
end
end
end
...
...
lib/paperclip/callback_compatability.rb
View file @
d8f45ee0
...
@@ -2,32 +2,80 @@ module Paperclip
...
@@ -2,32 +2,80 @@ module Paperclip
# This module is intended as a compatability shim for the differences in
# This module is intended as a compatability shim for the differences in
# callbacks between Rails 2.0 and Rails 2.1.
# callbacks between Rails 2.0 and Rails 2.1.
module
CallbackCompatability
module
CallbackCompatability
def
self
.
included
(
base
)
module
Rails20
base
.
extend
(
ClassMethods
)
def
self
.
included
(
base
)
base
.
send
(
:include
,
InstanceMethods
)
base
.
extend
(
Defining
)
base
.
send
(
:include
,
Running
)
puts
"Including Rails 2.0 Compatability"
end
module
Defining
def
define_paperclip_callbacks
(
*
args
)
end
end
module
Running
def
run_paperclip_callbacks
(
callback
,
opts
=
nil
,
&
blk
)
end
end
end
end
module
ClassMethods
module
Rails21
# The implementation of this method is taken from the Rails 1.2.6 source,
def
self
.
included
(
base
)
# from rails/activerecord/lib/active_record/callbacks.rb, line 192.
base
.
extend
(
Defining
)
def
define_callbacks
(
*
args
)
base
.
send
(
:include
,
Running
)
args
.
each
do
|
method
|
end
self
.
class_eval
<<-
"end_eval"
def self.
#{
method
}
(*callbacks, &block)
module
Defining
callbacks << block if block_given?
def
define_paperclip_callbacks
(
*
args
)
write_inheritable_array(
#{
method
.
to_sym
.
inspect
}
, callbacks)
args
.
each
do
|
callback
|
end
define_callbacks
(
"before_
#{
callback
}
"
)
end_eval
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
end
end
end
module
InstanceMethods
module
Rails3
# The callbacks in < 2.1 don't worry about the extra options or the
def
self
.
included
(
base
)
# block, so just run what we have available.
base
.
extend
(
Defining
)
def
run_callbacks
(
meth
,
opts
=
nil
,
&
blk
)
base
.
send
(
:include
,
Running
)
callback
(
meth
)
end
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
end
end
end
end
test/attachment_test.rb
View file @
d8f45ee0
...
@@ -399,12 +399,17 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -399,12 +399,17 @@ class AttachmentTest < Test::Unit::TestCase
end
end
should
"cancel the processing if a before_post_process returns false"
do
should
"cancel the processing if a before_post_process returns false"
do
begin
$DEBUG
=
true
@dummy
.
expects
(
:do_before_avatar
).
never
@dummy
.
expects
(
:do_before_avatar
).
never
@dummy
.
expects
(
:do_after_avatar
).
never
@dummy
.
expects
(
:do_after_avatar
).
never
@dummy
.
expects
(
:do_before_all
).
with
().
returns
(
false
)
@dummy
.
expects
(
:do_before_all
).
with
().
returns
(
false
)
@dummy
.
expects
(
:do_after_all
)
@dummy
.
expects
(
:do_after_all
)
Paperclip
::
Thumbnail
.
expects
(
:make
).
never
Paperclip
::
Thumbnail
.
expects
(
:make
).
never
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
ensure
$DEBUG
=
false
end
end
end
should
"cancel the processing if a before_avatar_post_process returns false"
do
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'
...
@@ -8,8 +8,9 @@ require 'mocha'
gem
'sqlite3-ruby'
gem
'sqlite3-ruby'
require
'active_record'
require
'activerecord'
require
'active_support'
require
'activesupport'
require
'actionpack'
begin
begin
require
'ruby-debug'
require
'ruby-debug'
rescue
LoadError
rescue
LoadError
...
@@ -94,8 +95,9 @@ class FakeModel
...
@@ -94,8 +95,9 @@ class FakeModel
@errors
||=
[]
@errors
||=
[]
end
end
def
run_callbacks
name
,
*
args
def
run_
paperclip_
callbacks
name
,
*
args
end
end
end
end
def
attachment
options
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