From 6134ed98a3fe29276a17a0d79a70a8ce3e3f548b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 7 Feb 2018 12:50:46 +0100 Subject: Add `ParentNotifier` service This is a takeoff on `ParentImportNotifier`. I just copied over the class and spec and generalised the service to work with `Import`-style interfaces. We can now use the same notifier service class for both imports and compliance check sets. Refs #4758 --- app/services/parent_notifier.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/services/parent_notifier.rb (limited to 'app/services') diff --git a/app/services/parent_notifier.rb b/app/services/parent_notifier.rb new file mode 100644 index 000000000..653c98aff --- /dev/null +++ b/app/services/parent_notifier.rb @@ -0,0 +1,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 -- cgit v1.2.3