1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/app/models/action_mailbox/inbound_email/incineratable.rb
2018-10-06 22:23:48 -04:00

28 lines
685 B
Ruby

module ActionMailbox::InboundEmail::Incineratable
extend ActiveSupport::Concern
included do
before_update :remember_to_incinerate_later
after_update_commit :incinerate_later, if: :incinerating_later?
end
def incinerate
Incineration.new(self).run
end
private
# TODO: Use enum change tracking once merged into Active Support
def remember_to_incinerate_later
if status_changed? && (delivered? || bounced? || failed?)
@incinerating_later = true
end
end
def incinerating_later?
@incinerating_later ||= false
end
def incinerate_later
ActionMailbox::InboundEmail::IncinerationJob.schedule(self)
end
end