Module: Namespaces::Traversal::Recursive

Extended by:
ActiveSupport::Concern
Includes:
RecursiveScopes
Included in:
Namespace
Defined in:
app/models/namespaces/traversal/recursive.rb

Instance Method Summary collapse

Instance Method Details

#all_project_idsObject Also known as: recursive_all_project_ids



22
23
24
25
# File 'app/models/namespaces/traversal/recursive.rb', line 22

def all_project_ids
  namespace = user_namespace? ? self : recursive_self_and_descendant_ids
  Project.where(namespace: namespace).select(:id)
end

#all_unarchived_project_idsObject Also known as: recursive_all_unarchived_project_ids



28
29
30
31
# File 'app/models/namespaces/traversal/recursive.rb', line 28

def all_unarchived_project_ids
  namespace = user_namespace? ? self : recursive_self_and_descendant_ids
  Project.self_and_ancestors_non_archived.where(namespace: namespace).select(:id)
end

#ancestor_ids(hierarchy_order: nil) ⇒ Object Also known as: recursive_ancestor_ids



50
51
52
# File 'app/models/namespaces/traversal/recursive.rb', line 50

def ancestor_ids(hierarchy_order: nil)
  recursive_ancestors(hierarchy_order: hierarchy_order).pluck(:id)
end

#ancestors(hierarchy_order: nil, skope: self.class) ⇒ Object Also known as: recursive_ancestors

Returns all the ancestors of the current namespaces.



42
43
44
45
46
47
# File 'app/models/namespaces/traversal/recursive.rb', line 42

def ancestors(hierarchy_order: nil, skope: self.class)
  return skope.none unless parent_id

  object_hierarchy(skope.where(id: parent_id))
    .base_and_ancestors(hierarchy_order: hierarchy_order)
end

#ancestors_upto(top = nil, hierarchy_order: nil) ⇒ Object Also known as: recursive_ancestors_upto

returns all ancestors upto but excluding the given namespace when no namespace is given, all ancestors upto the top are returned



57
58
59
60
# File 'app/models/namespaces/traversal/recursive.rb', line 57

def ancestors_upto(top = nil, hierarchy_order: nil)
  object_hierarchy(self.class.where(id: id))
    .ancestors(upto: top, hierarchy_order: hierarchy_order)
end

#descendantsObject Also known as: recursive_descendants

Returns all the descendants of the current namespace.



77
78
79
# File 'app/models/namespaces/traversal/recursive.rb', line 77

def descendants
  object_hierarchy(self.class.where(parent_id: id)).base_and_descendants
end

#object_hierarchy(ancestors_base) ⇒ Object



92
93
94
# File 'app/models/namespaces/traversal/recursive.rb', line 92

def object_hierarchy(ancestors_base)
  Gitlab::ObjectHierarchy.new(ancestors_base)
end

#root_ancestorObject Also known as: recursive_root_ancestor



9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/namespaces/traversal/recursive.rb', line 9

def root_ancestor
  if persisted? && !parent_id.nil?
    strong_memoize(:root_ancestor) do
      recursive_ancestors.without_order.find_top_level
    end
  elsif parent.nil?
    self
  else
    parent.root_ancestor
  end
end

#self_and_ancestor_ids(hierarchy_order: nil) ⇒ Object Also known as: recursive_self_and_ancestor_ids



71
72
73
# File 'app/models/namespaces/traversal/recursive.rb', line 71

def self_and_ancestor_ids(hierarchy_order: nil)
  recursive_self_and_ancestors(hierarchy_order: hierarchy_order).pluck(:id)
end

#self_and_ancestors(hierarchy_order: nil, skope: self.class) ⇒ Object Also known as: recursive_self_and_ancestors



63
64
65
66
67
68
# File 'app/models/namespaces/traversal/recursive.rb', line 63

def self_and_ancestors(hierarchy_order: nil, skope: self.class)
  return skope.where(id: id) unless parent_id

  object_hierarchy(skope.where(id: id))
    .base_and_ancestors(hierarchy_order: hierarchy_order)
end

#self_and_descendant_ids(skope: self.class) ⇒ Object Also known as: recursive_self_and_descendant_ids



87
88
89
# File 'app/models/namespaces/traversal/recursive.rb', line 87

def self_and_descendant_ids(skope: self.class)
  object_hierarchy(skope.where(id: id)).base_and_descendant_ids
end

#self_and_descendants(skope: self.class) ⇒ Object Also known as: recursive_self_and_descendants



82
83
84
# File 'app/models/namespaces/traversal/recursive.rb', line 82

def self_and_descendants(skope: self.class)
  object_hierarchy(skope.where(id: id)).base_and_descendants
end

#self_and_hierarchyObject Also known as: recursive_self_and_hierarchy

Returns all ancestors, self, and descendants of the current namespace.



35
36
37
38
# File 'app/models/namespaces/traversal/recursive.rb', line 35

def self_and_hierarchy
  object_hierarchy(self.class.where(id: id))
    .all_objects
end