なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2018/12/27)

2018/12/27分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

actionmailbox/CHANGELOG.md


Merge pull request #34786 from georgeclaghorn/actionmailbox

メールの受信処理を行う為のAction MailboxコンポーネントRails本体にインポートしています。

デフォルトでAmazon SES, Mailgun, Mandrill, SendGrid及びPostfixをサポートしています。

サポートしている各サービス毎にcontrollerが用意されており、メールを受信するとそれらcontrollerでActive Storageを使用して元のメールをcloud storageに保存するようになっています。

Action Mailbox用のテーブル(action_mailbox_inbound_emails)があり、そちらではメールのstatusが管理されるようになっています。メールの情報はDBには保存しないようになっており、メールの情報を参照する際は、Active Storageを経由してcloud storageにあるファイルを参照するようになっています。

cloud storageに保存したメールは自動で削除されるようになっており、デフォルトでは30日後に削除されるようになっています。この値はconfigで変更可能。

また、メールを受信後、自動で返信・転送も出来るようになっています。これらは独自のmailboxクラスで処理を定義出来るようになっています。以下転送の例。

# app/mailboxes/forwards_mailbox.rb
class ForwardsMailbox < ApplicationMailbox
  # Callbacks specify prerequisites to processing
  before_processing :require_forward

  def process
    if forwarder.buckets.one?
      record_forward
    else
      stage_forward_and_request_more_details
    end
  end

  private
    def require_forward
      unless message.forward?
        # Use Action Mailers to bounce incoming emails back to sender – this halts processing
        bounce_with Forwards::BounceMailer.missing_forward(
          inbound_email, forwarder: forwarder
        )
      end
    end

    def forwarder
      @forwarder ||= Person.where(email_address: mail.from)
    end

    def record_forward
      forwarder.buckets.first.record \
        Forward.new forwarder: forwarder, subject: message.subject, content: mail.content
    end

    def stage_forward_and_request_more_details
      Forwards::RoutingMailer.choose_project(mail).deliver_now
    end
end

諸々詳細は、README参照。


Test against Ruby 2.6.0

.travis.ymlの修正です。

CIでRuby 2.6.0に対してテストを実行するよう修正しています。


Start an Action Mailbox changelog

actionmailbox/CHANGELOG.mdの修正です。

Action MailboxのCHANGELOG.mdを追加しています。


Generate Action Mailbox's API docs

railties/lib/rails/api/task.rbの修正です。

API docでAction Mailboxのdocを生成するよう修正しています。


Nest Action Mailbox classes in the API docs

Action Mailboxの修正です。

classをnestして定義する(e.g. class ActionMailbox::BaseControllermodule ActionMailbox; class BaseControllerに変更)よう修正しています。

コンポーネントでmoduleを切り出しておかないと、API docが期待通りに生成されない為のはず。


Nest ActionMailbox::Base in the API docs (missed in 6c168aa)

actionmailbox/lib/action_mailbox/base.rbの修正です。

先のclassのnest対応で、対応が漏れている箇所があったのを修正しています。


Improve actionmailbox's .gitignore and remove redundant files

Action Mailboxの修正です。

.gitignoreから不要な記載を削除、リポジトリに入れるべきではないログファイルの削除等を行っています。


Fix Ruby warnings in actionmailbox

actionmailbox/app/models/action_mailbox/inbound_email/message_id.rbの修正です。

ActionMailbox::InboundEmail::MessageId#create_and_extract_message_idメソッドRubyのwarningが出ていたのを修正しています。


Reuse AR::Association#find_target method

Active Recordの修正です。

CollectionAssociationSingularAssociationそれぞれで定義していたfind_targetメソッドを親クラスのAssociationに定義し、処理を共通化するよう修正しています。Merge pull request #34538 from bogdan/reuse-find-targetのリトライ。


Only run isolated tests on the latest stable ruby: that's now 2.6

ci/travis.rbの修正です。

isolated testがRuby 2.5、2.6両方で実行されていたのを、最新の安定版のRuby(2.6)でだけ実行されるよう修正しています。isolated testは時間が掛かる為。