2018-12-14 05:06:12 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-28 15:19:43 -04:00
|
|
|
require "active_support/callbacks"
|
|
|
|
|
|
|
|
module ActionMailbox
|
2018-12-12 20:13:26 -05:00
|
|
|
# Defines the callbacks related to processing.
|
2018-09-28 15:19:43 -04:00
|
|
|
module Callbacks
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include ActiveSupport::Callbacks
|
|
|
|
|
2018-10-06 22:15:36 -04:00
|
|
|
TERMINATOR = ->(mailbox, chain) do
|
|
|
|
chain.call
|
|
|
|
mailbox.finished_processing?
|
2018-10-03 15:36:40 -04:00
|
|
|
end
|
|
|
|
|
2018-09-28 15:19:43 -04:00
|
|
|
included do
|
2018-10-03 16:04:33 -04:00
|
|
|
define_callbacks :process, terminator: TERMINATOR, skip_after_callbacks_if_terminated: true
|
2018-09-28 15:19:43 -04:00
|
|
|
end
|
|
|
|
|
2018-12-19 16:51:42 -05:00
|
|
|
class_methods do
|
2018-09-28 15:19:43 -04:00
|
|
|
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
|