From 4b5e1e982740723648638ab06fbe7e38e2e70dc1 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Sep 2018 16:40:56 -0700 Subject: Extract routable concern --- app/models/action_mailroom/inbound_email.rb | 13 ++----------- app/models/action_mailroom/inbound_email/routable.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 app/models/action_mailroom/inbound_email/routable.rb (limited to 'app/models/action_mailroom') diff --git a/app/models/action_mailroom/inbound_email.rb b/app/models/action_mailroom/inbound_email.rb index d44007c2f1..c439988e91 100644 --- a/app/models/action_mailroom/inbound_email.rb +++ b/app/models/action_mailroom/inbound_email.rb @@ -1,23 +1,14 @@ require "mail" class ActionMailroom::InboundEmail < ActiveRecord::Base - include Incineratable - self.table_name = "action_mailroom_inbound_emails" - has_one_attached :raw_email + 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 diff --git a/app/models/action_mailroom/inbound_email/routable.rb b/app/models/action_mailroom/inbound_email/routable.rb new file mode 100644 index 0000000000..b888c592f5 --- /dev/null +++ b/app/models/action_mailroom/inbound_email/routable.rb @@ -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 -- cgit v1.2.3