Class: Pages::LookupPath

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/models/pages/lookup_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deployment:, root_namespace_id:, domain: nil, trim_prefix: nil, access_control: false) ⇒ LookupPath

Returns a new instance of LookupPath.



7
8
9
10
11
12
13
14
# File 'app/models/pages/lookup_path.rb', line 7

def initialize(deployment:, root_namespace_id:, domain: nil, trim_prefix: nil, access_control: false)
  @deployment = deployment
  @project = deployment.project
  @root_namespace_id = root_namespace_id
  @domain = domain
  @trim_prefix = trim_prefix || @project.full_path
  @access_control = access_control
end

Instance Attribute Details

#access_controlObject

Returns the value of attribute access_control.



16
17
18
# File 'app/models/pages/lookup_path.rb', line 16

def access_control
  @access_control
end

Instance Method Details

#https_onlyObject



23
24
25
26
# File 'app/models/pages/lookup_path.rb', line 23

def https_only
  domain_https = domain ? domain.https? : true
  project.pages_https_only? && domain_https
end

#prefixObject



47
48
49
# File 'app/models/pages/lookup_path.rb', line 47

def prefix
  ensure_leading_and_trailing_slash(prefix_value)
end

#primary_domainObject



70
71
72
# File 'app/models/pages/lookup_path.rb', line 70

def primary_domain
  project&.project_setting&.pages_primary_domain
end

#project_idObject



18
19
20
# File 'app/models/pages/lookup_path.rb', line 18

def project_id
  project.id
end

#root_directoryObject



63
64
65
66
67
# File 'app/models/pages/lookup_path.rb', line 63

def root_directory
  return unless deployment

  deployment.root_directory
end

#sourceObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/pages/lookup_path.rb', line 29

def source
  return unless deployment&.file

  global_id = ::Gitlab::GlobalId.build(deployment, id: deployment.id).to_s

  {
    type: 'zip',
    path: deployment.file.url_or_file_path(
      expire_at: ::Gitlab::Pages::DEPLOYMENT_EXPIRATION.from_now
    ),
    global_id: global_id,
    sha256: deployment.file_sha256,
    file_size: deployment.size,
    file_count: deployment.file_count
  }
end

#unique_hostObject



52
53
54
55
56
57
58
59
60
# File 'app/models/pages/lookup_path.rb', line 52

def unique_host
  # When serving custom domain we don't present the unique host to avoid
  # GitLab Pages auto-redirect to the unique domain instead of keeping serving
  # from the custom domain.
  # https://gitlab.com/gitlab-org/gitlab/-/issues/426435
  return if domain.present?

  project.pages_url_builder.unique_host
end