Class: RoRmaily::Mailer

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
app/mailers/maily_herald/mailer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#entityObject (readonly)

Returns the value of attribute entity


3
4
5
# File 'app/mailers/maily_herald/mailer.rb', line 3

def entity
  @entity
end

Class Method Details

.deliver_mail(mail) ⇒ Object

TODO make it instance method so we get access to instance attributes


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/mailers/maily_herald/mailer.rb', line 23

def deliver_mail(mail) #:nodoc:
  mailing = mail.ror_maily_data[:mailing]
  entity = mail.ror_maily_data[:entity]


  if mailing && entity
    mailing.deliver_with_mailer_to(entity) do
      ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
        self.set_payload_for_mail(payload, mail)
        yield # Let Mail do the delivery actions
      end
      mail
    end
  else
    RoRmaily.logger.log_processing(mailing, entity, mail, prefix: "Delivery outside Maily")

    ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
      self.set_payload_for_mail(payload, mail)
      yield # Let Mail do the delivery actions
    end
  end
end

Instance Method Details

#generic(entity, mailing) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/mailers/maily_herald/mailer.rb', line 5

def generic entity, mailing
  destination = mailing.destination(entity)
  subject = mailing.render_subject(entity)
  content = mailing.render_template(entity)

  opts = {
    to: destination, 
    subject: subject
  }
  opts[:from] = mailing.from if mailing.from.present?

  mail(opts) do |format|
    format.text { render text: content }
  end
end

#mail(headers = {}, &block) ⇒ Object


47
48
49
50
51
52
53
54
55
56
# File 'app/mailers/maily_herald/mailer.rb', line 47

def mail(headers = {}, &block)
  return @_message if @_mail_was_called && headers.blank? && !block

  # Assign instance variables availabe for template
  @maily_subscription = @_message.ror_maily_data[:subscription]
  @maily_entity = @_message.ror_maily_data[:entity]
  @maily_mailing = @_message.ror_maily_data[:mailing]

  super
end