Class: Eventifier::Delivery
- Inherits:
-
Object
- Object
- Eventifier::Delivery
- Defined in:
- lib/eventifier/delivery.rb
Class Method Summary collapse
Instance Method Summary collapse
- #deliver ⇒ Object
-
#initialize(user, notifications) ⇒ Delivery
constructor
A new instance of Delivery.
Constructor Details
#initialize(user, notifications) ⇒ Delivery
Returns a new instance of Delivery.
13 14 15 |
# File 'lib/eventifier/delivery.rb', line 13 def initialize(user, notifications) @user, @notifications = user, notifications end |
Class Method Details
.deliver ⇒ Object
2 3 4 5 6 7 |
# File 'lib/eventifier/delivery.rb', line 2 def self.deliver unsent = Eventifier::Notification.unsent unsent.group_by(&:user).each do |user, notifications| new(user, notifications).deliver end end |
.deliver_for(user) ⇒ Object
9 10 11 |
# File 'lib/eventifier/delivery.rb', line 9 def self.deliver_for(user) new(user, user.notifications.unsent).deliver end |
Instance Method Details
#deliver ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/eventifier/delivery.rb', line 17 def deliver if anything_to_send? && user_receives_emails? Eventifier.mailer.notifications(user, notifications_to_send).deliver end notifications.each do |notification| notification.update_attribute :sent, true end end |