0
@@ -116,41 +116,47 @@ module Technoweenie # :nodoc:
0
content_types.include?(content_type)
0
- # Callback after an image has been resized.
0
- # class Foo < ActiveRecord::Base
0
- # after_resize do |record, img|
0
- # record.aspect_ratio = img.columns.to_f / img.rows.to_f
0
- def after_resize(&block)
0
- write_inheritable_array(:after_resize, [block])
0
+ if defined?(::ActiveSupport::Callbacks)
0
+ def self.extended(base)
0
+ base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
0
+ # Callback after an image has been resized.
0
+ # class Foo < ActiveRecord::Base
0
+ # after_resize do |record, img|
0
+ # record.aspect_ratio = img.columns.to_f / img.rows.to_f
0
+ def after_resize(&block)
0
+ write_inheritable_array(:after_resize, [block])
0
- # Callback after an attachment has been saved either to the file system or the DB.
0
- # Only called if the file has been changed, not necessarily if the record is updated.
0
- # class Foo < ActiveRecord::Base
0
- # after_attachment_saved do |record|
0
- def after_attachment_saved(&block)
0
- write_inheritable_array(:after_attachment_saved, [block])
0
+ # Callback after an attachment has been saved either to the file system or the DB.
0
+ # Only called if the file has been changed, not necessarily if the record is updated.
0
+ # class Foo < ActiveRecord::Base
0
+ # after_attachment_saved do |record|
0
+ def after_attachment_saved(&block)
0
+ write_inheritable_array(:after_attachment_saved, [block])
0
- # Callback before a thumbnail is saved. Use this to pass any necessary extra attributes that may be required.
0
- # class Foo < ActiveRecord::Base
0
- # before_thumbnail_saved do |record, thumbnail|
0
- def before_thumbnail_saved(&block)
0
- write_inheritable_array(:before_thumbnail_saved, [block])
0
+ # Callback before a thumbnail is saved. Use this to pass any necessary extra attributes that may be required.
0
+ # class Foo < ActiveRecord::Base
0
+ # before_thumbnail_saved do |record, thumbnail|
0
+ def before_thumbnail_saved(&block)
0
+ write_inheritable_array(:before_thumbnail_saved, [block])
0
# Get the thumbnail class, which is the current attachment class by default.
0
@@ -397,10 +403,30 @@ module Technoweenie # :nodoc:
0
result = callback.call(self, arg)
0
return false if result == false
0
+ # Rather ugly monkey-patch of AS::Callbacks to support taking an arg
0
+ if defined?(::ActiveSupport::Callbacks)
0
+ def callbacks_for(method) #:nodoc: compatibility method
0
+ self.class.send("#{method}_callback_chain")
0
+ class ::ActiveSupport::Callbacks::Callback
0
+ # Make callbacks accept arguments, but only pass them along to procs for now
0
+ def call(object, *args)
0
+ if should_run_callback?(object)
0
+ args = [object, *args].compact
0
+ evaluate_method(method, object)
0
# Removes the thumbnails for the attachment, if it has any
0
self.thumbnails.each { |thumbnail| thumbnail.destroy } if thumbnailable?
Comments
No one has commented yet.