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:
parent
3e199600ec
commit
4b5e1e9827
2 changed files with 14 additions and 11 deletions
|
@ -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
|
||||
|
|
12
app/models/action_mailroom/inbound_email/routable.rb
Normal file
12
app/models/action_mailroom/inbound_email/routable.rb
Normal 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
|
Loading…
Reference in a new issue