aboutsummaryrefslogblamecommitdiffstats
path: root/lib/action_mailbox/callbacks.rb
blob: e8bf2ffd557d33557fb549dc2fbdf84ca9bdf160 (plain) (tree)
1
2
3
4
5
6
7






                                    










                                                 
               
                                                       
















                                                         
require "active_support/callbacks"

module ActionMailbox
  module Callbacks
    extend  ActiveSupport::Concern
    include ActiveSupport::Callbacks

    TERMINATOR = ->(target, chain) do
      terminate = true

      catch(:abort) do
        chain.call
        terminate = target.inbound_email.bounced?
      end

      terminate
    end

    included do
      define_callbacks :process, terminator: TERMINATOR
    end

    module ClassMethods
      def before_processing(*methods, &block)
        set_callback(:process, :before, *methods, &block)
      end

      def after_processing(*methods, &block)
        set_callback(:process, :after, *methods, &block)
      end

      def around_processing(*methods, &block)
        set_callback(:process, :around, *methods, &block)
      end
    end
  end
end