1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
# frozen_string_literal: true
module Pages
class VirtualDomain
def initialize(projects:, trim_prefix: nil, domain: nil)
@projects = projects
@trim_prefix = trim_prefix
@domain = domain
end
def certificate
domain&.certificate
end
def key
domain&.key
end
def lookup_paths
projects.flat_map { |project| lookup_paths_for(project) }
end
private
attr_reader :projects, :trim_prefix, :domain
def lookup_paths_for(project)
deployments_for(project).map do |deployment|
Pages::LookupPath.new(
deployment: deployment,
trim_prefix: trim_prefix,
domain: domain)
end
end
def deployments_for(project)
if ::Gitlab::Pages.multiple_versions_enabled_for?(project)
project.active_pages_deployments
else
# project.active_pages_deployments is already loaded from the database,
# so finding from the array to avoid N+1
project
.active_pages_deployments
.to_a
.find { |deployment| deployment.path_prefix.blank? }
.then { |deployment| [deployment] }
end
end
end
end
|