Class: Effective::NotificationsMailer

Inherits:
Object
  • Object
show all
Includes:
EffectiveMailer
Defined in:
app/mailers/effective/notifications_mailer.rb

Instance Method Summary collapse

Instance Method Details

#notify(notification, opts = {}) ⇒ Object

This is not an EffectiveEmailTemplatesMailer



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/mailers/effective/notifications_mailer.rb', line 7

def notify(notification, opts = {})
  raise('expected an Effective::Notification') unless notification.kind_of?(Effective::Notification)

  # Returns a Hash of params to pass to mail()
  # Includes a :to, :from, :subject and :body, etc
  rendered = notification.assign_renderer(view_context).render_email

  # Attach report
  attach_report!(notification)
  rendered.delete(:content_type) if notification.attach_report?

  # Works with effective_logging to associate this email with the notification
  headers = headers_for(notification, opts)

  # Use postmark broadcast-stream
  if defined?(Postmark)
    headers.merge!(message_stream: 'broadcast-stream') 
    attach_unsubscribe_link!(rendered)
  end

  # Calls effective_resources subject proc, so we can prepend [LETTERS]
  subject = subject_for(__method__, rendered.fetch(:subject), notification, opts)

  # Pass everything to mail
  mail(rendered.merge(headers).merge(subject: subject))
end

#notify_resource(notification, resource, opts = {}) ⇒ Object

Does not use effective_email_templates mailer



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/mailers/effective/notifications_mailer.rb', line 35

def notify_resource(notification, resource, opts = {})
  raise('expected an Effective::Notification') unless notification.kind_of?(Effective::Notification)
  raise('expected an acts_as_reportable resource') unless resource.class.try(:acts_as_reportable?)

  # Returns a Hash of params to pass to mail()
  # Includes a :to, :from, :subject and :body
  rendered = notification.assign_renderer(view_context).render_email(resource)

  # Works with effective_logging to associate this email with the notification
  headers = headers_for(notification, opts)

  # Use postmark broadcast-stream
  if defined?(Postmark)
    headers.merge!(message_stream: 'broadcast-stream') 
    attach_unsubscribe_link!(rendered)
  end

  # Calls effective_resources subject proc, so we can prepend [LETTERS]
  subject = subject_for(__method__, rendered.fetch(:subject), resource, opts)

  # Pass everything to mail
  mail(rendered.merge(headers).merge(subject: subject))
end