summaryrefslogtreecommitdiff
path: root/app/graphql/types/concerns/find_closest.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/graphql/types/concerns/find_closest.rb')
-rw-r--r--app/graphql/types/concerns/find_closest.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/graphql/types/concerns/find_closest.rb b/app/graphql/types/concerns/find_closest.rb
new file mode 100644
index 00000000000..1d76e872364
--- /dev/null
+++ b/app/graphql/types/concerns/find_closest.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module FindClosest
+ # Find the closest node of a given type above this node, and return the domain object
+ def closest_parent(type, parent)
+ parent = parent.try(:parent) while parent && parent.object.class != type
+ return unless parent
+
+ parent.object.object
+ end
+end