Class: Eventifier::Delivery

Inherits:
Object
  • Object
show all
Defined in:
lib/eventifier/delivery.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.deliverObject



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

#deliverObject



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