forked from thoughtbot/paperclip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a callback compatability shim for older versions of Rails
- Loading branch information
Jon Yurek
committed
Dec 29, 2008
1 parent
1d02330
commit b8506d3
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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 | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
base.send(:include, InstanceMethods) | ||
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) | ||
end | ||
end_eval | ||
end | ||
end | ||
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) | ||
end | ||
end | ||
end | ||
end |