Class: SendgridNotification::NotificationMail

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sendgrid_notification/notification_mail.rb

Constant Summary collapse

VARIABLE_REGEXP_DEFAULT =
/\{\{\s*(\w+)\s*\}\}/

Instance Method Summary collapse

Instance Method Details

#apply(params) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/sendgrid_notification/notification_mail.rb', line 27

def apply(params)
  unresolved = []
  body = content.gsub(variable_regexp) { |_|
    key = $1
    params[key] || params[key.to_sym] || unresolved.push(key)
  }
  if unresolved.present?
    errors.add(:content, :unresolved_template_parameters, variables: unresolved.join(","))
  end
  body
end

#sendmail_later(to, params, attachments = []) ⇒ Object Also known as: sendmail



15
16
17
18
# File 'app/models/sendgrid_notification/notification_mail.rb', line 15

def sendmail_later(to, params, attachments = [])
  hash_attachments = attachments.map(&:to_h)
  SendmailJob.perform_later(to, self, params, hash_attachments)
end

#sendmail_now(to, params, attachments = []) ⇒ Object



22
23
24
25
# File 'app/models/sendgrid_notification/notification_mail.rb', line 22

def sendmail_now(to, params, attachments = [])
  hash_attachments = attachments.map(&:to_h)
  SendmailJob.perform_now(to, self, params, hash_attachments)
end