Sha256: 96723e4e13b66613545d1d6ff0519a9d8117dbc066f7278ea82e98195e012862

Contents?: true

Size: 828 Bytes

Versions: 1

Compression:

Stored size: 828 Bytes

Contents

module Raddar
  class FollowershipCompletion
    def initialize(followership)
      @followership = followership
    end

    def create
      successful = @followership.save

      if successful
        notify_followed_user
      end

      successful
    end

    private

    def notify_followed_user
      followable = @followership.followable

      if followable.is_a?(User)
        notification            = Notification.new
        notification.user       = followable
        notification.token      = 'new_follower'
        notification.notifiable = @followership.user
        notification.save!

        email_preferences = followable.email_preferences || {}

        if email_preferences[:new_follower] != false
          NotificationMailer.new_follower(notification).deliver
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
raddar-0.0.1.pre app/models/raddar/followership_completion.rb