2021-08-05 05:08:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Namespaces
|
|
|
|
module Traversal
|
|
|
|
module RecursiveScopes
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
|
|
|
def as_ids
|
|
|
|
select('id')
|
|
|
|
end
|
|
|
|
|
2021-08-11 08:10:59 -04:00
|
|
|
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
|
2021-08-05 05:08:56 -04:00
|
|
|
end
|
|
|
|
alias_method :recursive_self_and_descendants, :self_and_descendants
|
|
|
|
|
2021-08-11 08:10:59 -04:00
|
|
|
def self_and_descendant_ids(include_self: true)
|
|
|
|
self_and_descendants(include_self: include_self).as_ids
|
2021-08-05 05:08:56 -04:00
|
|
|
end
|
|
|
|
alias_method :recursive_self_and_descendant_ids, :self_and_descendant_ids
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|