diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-18 16:42:38 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-18 16:42:38 -0700 |
commit | 0f140fe15852b829d22864a2f7664440204ac723 (patch) | |
tree | 588993cc03b29f98b643d92154b5417f5a53279e /lib | |
parent | 5f73fa84fff1b92665de7779c4cb824277930ca8 (diff) | |
download | rails-0f140fe15852b829d22864a2f7664440204ac723.tar.gz rails-0f140fe15852b829d22864a2f7664440204ac723.tar.bz2 rails-0f140fe15852b829d22864a2f7664440204ac723.zip |
Add callbacks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/action_mailroom/mailbox.rb | 9 | ||||
-rw-r--r-- | lib/action_mailroom/mailbox/callbacks.rb | 28 |
2 files changed, 35 insertions, 2 deletions
diff --git a/lib/action_mailroom/mailbox.rb b/lib/action_mailroom/mailbox.rb index 44dcd691b1..0d03f4be6b 100644 --- a/lib/action_mailroom/mailbox.rb +++ b/lib/action_mailroom/mailbox.rb @@ -1,7 +1,8 @@ require "active_support/rescuable" +require "action_mailroom/mailbox/callbacks" class ActionMailroom::Mailbox - include ActiveSupport::Rescuable + include ActiveSupport::Rescuable, Callbacks class << self def receive(inbound_email) @@ -22,7 +23,11 @@ class ActionMailroom::Mailbox def perform_processing inbound_email.processing! - process + + run_callbacks :process do + process + end + inbound_email.delivered! rescue => exception inbound_email.failed! diff --git a/lib/action_mailroom/mailbox/callbacks.rb b/lib/action_mailroom/mailbox/callbacks.rb new file mode 100644 index 0000000000..ae5a461d8f --- /dev/null +++ b/lib/action_mailroom/mailbox/callbacks.rb @@ -0,0 +1,28 @@ +require "active_support/callbacks" + +module ActionMailroom + class Mailbox + module Callbacks + extend ActiveSupport::Concern + include ActiveSupport::Callbacks + + included do + define_callbacks :process + 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 +end |