Skip to content

Instantly share code, notes, and snippets.

@danielvlopes
Created July 2, 2015 17:01
Show Gist options
  • Save danielvlopes/48bfd44465f71f213715 to your computer and use it in GitHub Desktop.
Save danielvlopes/48bfd44465f71f213715 to your computer and use it in GitHub Desktop.
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