Class: Notifier

Inherits:
ApplicationMailer show all
Defined in:
app/mailers/notifier.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.admin(string, recipients, opts = {}, subject = nil) ⇒ Object


8
9
10
11
12
13
14
15
# File 'app/mailers/notifier.rb', line 8

def self.admin(string, recipients, opts = {}, subject=nil)
  mails = []
  recipients.each do |rec|
    mail = single_admin(string, rec, opts.dup, subject)
    mails << mail
  end
  mails
end

Instance Method Details

#invite(email, inviter, invitation_code, locale) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/mailers/notifier.rb', line 42

def invite(email, inviter, invitation_code, locale)
  @inviter = inviter
  @invitation_code = invitation_code

  I18n.with_locale(locale) do
    mail_opts = {to: email, from: "\"#{AppConfig.settings.pod_name}\" <#{AppConfig.mail.sender_address}>",
               subject: I18n.t("notifier.invited_you", name: @inviter.name),
               host: AppConfig.pod_uri.host}

    mail(mail_opts) do |format|
      format.text { render :layout => nil }
      format.html { render :layout => nil }
    end
  end
end

#send_notification(type, *args) ⇒ Object


58
59
60
61
62
63
64
65
66
67
68
# File 'app/mailers/notifier.rb', line 58

def send_notification(type, *args)
  @notification = NotificationMailers.const_get(type.to_s.camelize).new(*args)

  with_recipient_locale do
    mail(@notification.headers) do |format|
      self.action_name = type
      format.text
      format.html
    end
  end
end

#single_admin(string, recipient, opts = {}, subject = nil) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/mailers/notifier.rb', line 17

def single_admin(string, recipient, opts={}, subject=nil)
  @receiver = recipient
  @string = string.html_safe

  if attach = opts.delete(:attachments)
    attach.each{ |f|
      attachments[f[:name]] = f[:file]
    }
  end

  unless subject
    subject = I18n.t('notifier.single_admin.subject')
  end

  default_opts = {:to => @receiver.email,
       :from => AppConfig.mail.sender_address,
       :subject => subject, :host => AppConfig.pod_uri.host}
  default_opts.merge!(opts)

  mail(default_opts) do |format|
    format.text
    format.html
  end
end