debian-mirror-gitlab/app/models/namespaces/traversal/recursive_scopes.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.9 KiB
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
module Namespaces
module Traversal
module RecursiveScopes
extend ActiveSupport::Concern
class_methods do
def as_ids
select('id')
end
2021-12-11 22:18:48 +05:30
def roots
Gitlab::ObjectHierarchy
.new(all)
.base_and_ancestors
.where(namespaces: { parent_id: nil })
end
2022-03-02 08:16:31 +05:30
def self_and_ancestors(include_self: true, upto: nil, hierarchy_order: nil)
records = Gitlab::ObjectHierarchy.new(all).base_and_ancestors(upto: upto, hierarchy_order: hierarchy_order)
2021-11-11 11:23:49 +05:30
if include_self
records
else
records.where.not(id: all.as_ids)
end
end
alias_method :recursive_self_and_ancestors, :self_and_ancestors
def self_and_ancestor_ids(include_self: true)
self_and_ancestors(include_self: include_self).as_ids
end
alias_method :recursive_self_and_ancestor_ids, :self_and_ancestor_ids
2021-10-27 15:23:28 +05:30
def descendant_ids
recursive_descendants.as_ids
end
alias_method :recursive_descendant_ids, :descendant_ids
def self_and_descendants(include_self: true)
base = if include_self
unscoped.where(id: all.as_ids)
else
unscoped.where(parent_id: all.as_ids)
end
Gitlab::ObjectHierarchy.new(base).base_and_descendants
end
alias_method :recursive_self_and_descendants, :self_and_descendants
def self_and_descendant_ids(include_self: true)
self_and_descendants(include_self: include_self).as_ids
end
alias_method :recursive_self_and_descendant_ids, :self_and_descendant_ids
2022-04-04 11:22:00 +05:30
def self_and_hierarchy
Gitlab::ObjectHierarchy.new(all).all_objects
end
alias_method :recursive_self_and_hierarchy, :self_and_hierarchy
2021-10-27 15:23:28 +05:30
end
end
end
end