Welcome to mirror list, hosted at ThFree Co, Russian Federation.

email_inviter.rb « lib - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dee190c7ce5cd14f04cd0e0bcbaa75473c1ee6f5 (plain)
1
2
3
4
5
6
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
# frozen_string_literal: true

class EmailInviter
  attr_accessor :emails, :inviter, :locale

  def initialize(emails, inviter, options={})
    options = options.symbolize_keys
    self.locale = options.fetch(:locale, 'en')
    self.inviter = inviter
    self.emails = emails
  end

  def emails=(list)
    emails = list.split(%r{[,\s]+})
    emails.reject!{|x| x == inviter.email } unless inviter.nil?
    @emails = emails
  end

  def invitation_code
    @invitation_code ||= inviter.invitation_code
  end

  def send!
    self.emails.each{ |email| mail(email)}
  end

  private

  def mail(email)
    Notifier.invite(email, inviter, invitation_code, locale).deliver_now
  end
end