Welcome to mirror list, hosted at ThFree Co, Russian Federation.

find_closest.rb « concerns « types « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3064db19ea0e664062b47ed0f33cb1e0488ea7b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# frozen_string_literal: true

module FindClosest
  # 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

      if types.any? {|type| parent.object.instance_of? type}
        return parent.object.object
      else
        parent = parent.try(:parent)
      end
    end
  end
end