Module: NotifyOn::EmailSupport

Included in:
Notification
Defined in:
app/models/concerns/notify_on/email_support.rb

Instance Method Summary collapse

Instance Method Details

#email_attachmentsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/concerns/notify_on/email_support.rb', line 29

def email_attachments
  attachments = []
  return attachments unless email_config? && email_config.attachments?
  email_config.attachments.each do |name, renderer|
    next unless trigger.send(renderer.if) if renderer.try(:if?)
    filename = begin
      trigger.send(name)
    rescue => e
      name
    end
    begin
      file = if renderer.is_a?(Symbol)
        trigger.send(renderer)
      else
        trigger.send(renderer.file)
      end
    rescue => e
      raise "Could not create file: #{filename}\n#{e}"
    end
    attachments << { :name => filename, :file => file }
  end
  attachments
end

#email_fromObject



16
17
18
# File 'app/models/concerns/notify_on/email_support.rb', line 16

def email_from
  convert_string(email_from_raw)
end

#email_subjectObject



20
21
22
23
# File 'app/models/concerns/notify_on/email_support.rb', line 20

def email_subject
  return email_config.subject if email_config? && email_config.subject?
  description
end

#email_templateObject



11
12
13
14
# File 'app/models/concerns/notify_on/email_support.rb', line 11

def email_template
  return nil unless email_config?
  email_config.template || 'notify'
end

#send_email!Object



4
5
6
7
8
9
# File 'app/models/concerns/notify_on/email_support.rb', line 4

def send_email!
  return false unless can_send_email?
  NotifyOn.configuration.mailer_class.constantize
          .notify(id, email_template, email_attachments)
          .send("deliver_#{email_delivery_timing}")
end

#should_save_email_id?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/concerns/notify_on/email_support.rb', line 25

def should_save_email_id?
  email_config? && email_config.save_id?
end