lib/mongoid-paperclip.rb in glebtv-mongoid-paperclip-0.2.1 vs lib/mongoid-paperclip.rb in glebtv-mongoid-paperclip-0.2.2

- old
+ new

@@ -65,9 +65,40 @@ # field :avatar_content_type, :type => String # field :avatar_file_size, :type => Integer # field :avatar_updated_at, :type => DateTime # field :avatar_fingerprint, :type => String +# TODO Remove when https://github.com/thoughtbot/paperclip/issues/1403 is merged +require 'paperclip/callbacks' +module Paperclip + module Callbacks + module Defining + def define_paperclip_callbacks(*callbacks) + define_callbacks *[callbacks, {:terminator => callback_terminator}].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 + private + def callback_terminator + if ::ActiveSupport::VERSION::STRING >= '4.1' + lambda { |target, result| result == false } + else + 'result == false' + end + end + end + end +end + + module Mongoid module Paperclip extend ActiveSupport::Concern module ClassMethods