Sha256: 0f0fb0f6fcffca004e86c28836d999ef86647ae7beab536f01ce533db471aebe

Contents?: true

Size: 704 Bytes

Versions: 4

Compression:

Stored size: 704 Bytes

Contents

class UserEmail < ActiveRecord::Base
  
  belongs_to :user
  validates_uniqueness_of :email
  
  def activate!
    self.update_attribute(:active, true)
    self.user.flash = "Successfully re-activated #{self.email}."
    self.user.send_now = true
    self.user.save
  end
  
  def deactivate!
    self.update_attribute(:active, false)
    begin
      $mail.deliver(
        :from => 'sum@sumapp.com',
        :to => self.email,
        :subject => 'Sum deactivated',
        :body => 'Reply with the word "start" to begin receiving emails again.'
      )
      self.sent!
    rescue Exception
      self.increment!(:failures)
    end
  end
  
  def sent!
    self.update_attribute :failures, 0
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
winton-sum-0.1.0 lib/sum/model/user_email.rb
winton-sum-0.1.1 lib/sum/model/user_email.rb
sum-0.1.2 lib/sum/model/user_email.rb
sum-0.1.1 lib/sum/model/user_email.rb