Class: MailNotifyPreviewInterceptor
- Inherits:
-
Object
- Object
- MailNotifyPreviewInterceptor
- Defined in:
- lib/mail/notify/mail_notify_preview_interceptor.rb
Overview
This is a ActionMailer interceptor class for previews from the Notifications API
See ActionMailer::Base:
github.com/rails/rails/blob/v5.2.8.1/actionmailer/lib/action_mailer/base.rb#L367
Class Method Summary collapse
-
.previewing_email(message) ⇒ Object
ActionMailer call back when a preview is being generated.
Instance Method Summary collapse
-
#initialize(message) ⇒ MailNotifyPreviewInterceptor
constructor
Creates a new MailNotifyPreviewInterceptor ready for use.
-
#transform! ⇒ Object
Transforms the content of the message to that from the Notifications API preview.
Constructor Details
#initialize(message) ⇒ MailNotifyPreviewInterceptor
Creates a new MailNotifyPreviewInterceptor ready for use.
23 24 25 |
# File 'lib/mail/notify/mail_notify_preview_interceptor.rb', line 23 def initialize() @message = end |
Class Method Details
.previewing_email(message) ⇒ Object
ActionMailer call back when a preview is being generated.
Transforms the content of the passed in message.
16 17 18 |
# File 'lib/mail/notify/mail_notify_preview_interceptor.rb', line 16 def self.previewing_email() new().transform! end |
Instance Method Details
#transform! ⇒ Object
Transforms the content of the message to that from the Notifications API preview.
The html is wrapped in a layout and rendered by the MailNotifyPreviewsControllers renderer.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mail/notify/mail_notify_preview_interceptor.rb', line 32 def transform! # the messages delivery method will be our Mail::Notify::DeliveryMethod and have the `preview` method. preview = @message.delivery_method.preview(@message) @message.subject = preview.subject @message.html_part.body = renderer.render html: preview.html.html_safe, layout: "govuk_notify_layout" @message.text_part.body = preview.body @message end |