aboutsummaryrefslogtreecommitdiffstats
path: root/app/services/parent_notifier.rb
blob: 653c98afff4eb6834039f7f6f5a10245c36d23f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class ParentNotifier
  def initialize(klass)
    @klass = klass
  end

  def notify_when_finished(collection = nil)
    collection ||= objects_pending_notification
    collection.each(&:notify_parent)
  end

  def objects_pending_notification
    @klass
      .where(
        notified_parent_at: nil,
        status: @klass.finished_statuses
      )
      .where.not(parent: nil)
  end
end