Commit b8506d36 by Jon Yurek

Added a callback compatability shim for older versions of Rails

parent 1d023306
......@@ -83,6 +83,7 @@ module Paperclip
def included base #:nodoc:
base.extend ClassMethods
base.send(:include, Paperclip::CallbackCompatability) unless base.respond_to?(:define_callbacks)
end
def processor name
......
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment