1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Extract routable concern

This commit is contained in:
David Heinemeier Hansson 2018-09-19 16:40:56 -07:00
parent 3e199600ec
commit 4b5e1e9827
2 changed files with 14 additions and 11 deletions

View file

@ -1,23 +1,14 @@
require "mail"
class ActionMailroom::InboundEmail < ActiveRecord::Base
include Incineratable
self.table_name = "action_mailroom_inbound_emails"
include Incineratable, Routable
has_one_attached :raw_email
enum status: %i[ pending processing delivered failed bounced ]
after_create_commit :deliver_to_mailroom_later, if: ->(r) { r.pending? }
def mail
@mail ||= Mail.new(Mail::Utilities.binary_unsafe_to_crlf(raw_email.download))
end
private
def deliver_to_mailroom_later
ActionMailroom::RoutingJob.perform_later self
end
end

View file

@ -0,0 +1,12 @@
module ActionMailroom::InboundEmail::Routable
extend ActiveSupport::Concern
included do
after_create_commit :route_later, if: ->(r) { r.pending? }
end
private
def route_later
ActionMailroom::RoutingJob.perform_later self
end
end