diff options
Diffstat (limited to 'app/graphql/types/concerns/find_closest.rb')
-rw-r--r-- | app/graphql/types/concerns/find_closest.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/app/graphql/types/concerns/find_closest.rb b/app/graphql/types/concerns/find_closest.rb index 1d76e872364..3064db19ea0 100644 --- a/app/graphql/types/concerns/find_closest.rb +++ b/app/graphql/types/concerns/find_closest.rb @@ -1,11 +1,15 @@ # 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 + # Find the closest node which has any of the given types above this node, and return the domain object + def closest_parent(types, parent) + while parent - parent.object.object + if types.any? {|type| parent.object.instance_of? type} + return parent.object.object + else + parent = parent.try(:parent) + end + end end end |