debian-mirror-gitlab/app/models/pages/virtual_domain.rb

41 lines
874 B
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
module Pages
class VirtualDomain
2022-08-13 15:12:31 +05:30
def initialize(projects:, cache: nil, trim_prefix: nil, domain: nil)
2019-12-04 20:38:33 +05:30
@projects = projects
2022-08-13 15:12:31 +05:30
@cache = cache
2019-12-21 20:55:43 +05:30
@trim_prefix = trim_prefix
2019-12-04 20:38:33 +05:30
@domain = domain
end
def certificate
domain&.certificate
end
def key
domain&.key
end
def lookup_paths
2021-03-11 19:13:27 +05:30
paths = projects.map do |project|
2019-12-21 20:55:43 +05:30
project.pages_lookup_path(trim_prefix: trim_prefix, domain: domain)
2021-03-11 19:13:27 +05:30
end
2021-06-08 01:23:25 +05:30
# TODO: remove in https://gitlab.com/gitlab-org/gitlab/-/issues/328715
2021-03-11 19:13:27 +05:30
paths = paths.select(&:source)
paths.sort_by(&:prefix).reverse
2019-12-04 20:38:33 +05:30
end
2023-03-04 22:38:38 +05:30
# cache_key is required by #present_cached in ::API::Internal::Pages
2022-08-13 15:12:31 +05:30
def cache_key
@cache_key ||= cache&.cache_key
end
2019-12-04 20:38:33 +05:30
private
2022-08-13 15:12:31 +05:30
attr_reader :projects, :trim_prefix, :domain, :cache
2019-12-04 20:38:33 +05:30
end
end