Created
July 2, 2015 17:01
-
-
Save danielvlopes/48bfd44465f71f213715 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Notifiable | |
extend ActiveSupport::Concern | |
# def notification_mailer_class | |
# Implement this method | |
# end | |
def notified? | |
!notified_at.nil? | |
end | |
def notifiable? | |
!notified? && author.present? | |
end | |
def notify_participants! | |
notify course.active_participants | |
end | |
def notify_students! | |
notify course.active_students | |
end | |
def notified! | |
update notified_at: Time.now | |
end | |
private | |
def notify(scope) | |
return false unless notifiable? | |
scope. | |
where.not(users: {id: author.id}). | |
merge(Enrollment.wants_email_notifications). | |
each { |u| notification_mailer_class.notification(self, u).deliver_later } | |
notified! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment