aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2018-02-07 12:50:46 +0100
committerTeddy Wing2018-02-08 11:29:31 +0100
commit6134ed98a3fe29276a17a0d79a70a8ce3e3f548b (patch)
treef52fb6a48008171ce49546be300861155617f8fe /app
parentee1781d525bc04aff3f7f743be8297ee003ee9e0 (diff)
downloadchouette-core-6134ed98a3fe29276a17a0d79a70a8ce3e3f548b.tar.bz2
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
Diffstat (limited to 'app')
-rw-r--r--app/services/parent_notifier.rb19
1 files changed, 19 insertions, 0 deletions
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