Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 30 lines (24 sloc) 0.669 kb
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
class EmailInviter
  attr_accessor :emails, :message, :inviter, :locale

  def initialize(emails, inviter, options={})
    self.message = options[:message]
    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, message, inviter, invitation_code, locale).deliver!
  end
end
Something went wrong with that request. Please try again.