Sha256: bb4c590ffd43c92ffbbd785057018fbb591d2db0a31da11e566554fe6bdbabc8

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

require 'peoplefinder'

module Peoplefinder::Concerns::Notifications
  extend ActiveSupport::Concern

  included do
    def send_create_email!(current_user)
      if should_send_email_notification?(email, current_user)
        Peoplefinder::UserUpdateMailer.new_profile_email(
          self, current_user.email
        ).deliver
      end
    end

    def send_update_email!(current_user, old_email)
      if email == old_email
        notify_updates_to_unchanged_email_address current_user
      else
        notify_updates_to_changed_email_address current_user, old_email
      end
    end

    def notify_updates_to_unchanged_email_address(current_user)
      if should_send_email_notification?(email, current_user)
        Peoplefinder::UserUpdateMailer.updated_profile_email(
          self, current_user.email
        ).deliver
      end
    end

    def notify_updates_to_changed_email_address(current_user, old_email)
      if should_send_email_notification?(email, current_user)
        Peoplefinder::UserUpdateMailer.updated_address_to_email(
          self, current_user.email, old_email
        ).deliver
      end
      if should_send_email_notification?(old_email, current_user)
        Peoplefinder::UserUpdateMailer.updated_address_from_email(
          self, current_user.email, old_email
        ).deliver
      end
    end

    def send_destroy_email!(current_user)
      if should_send_email_notification?(email, current_user)
        Peoplefinder::UserUpdateMailer.deleted_profile_email(
          self, current_user.email
        ).deliver
      end
    end

  private

    def should_send_email_notification?(email, current_user)
      Peoplefinder::EmailAddress.new(email).valid_address? &&
        current_user.email != email
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
peoplefinder-0.1.1 app/models/peoplefinder/concerns/notifications.rb
peoplefinder-0.1.0 app/models/peoplefinder/concerns/notifications.rb
peoplefinder-0.0.2 app/models/peoplefinder/concerns/notifications.rb