Class: Pages::LookupPath

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

Constant Summary collapse

LegacyStorageDisabledError =
Class.new(::StandardError)

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(project, trim_prefix: nil, domain: nil) ⇒ LookupPath

Returns a new instance of LookupPath.


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

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

Instance Method Details

#access_controlObject


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

def access_control
  project.private_pages?
end

#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


43
44
45
46
47
48
49
# File 'app/models/pages/lookup_path.rb', line 43

def prefix
  if project.pages_group_root?
    '/'
  else
    project.full_path.delete_prefix(trim_prefix) + '/'
  end
end

#project_idObject


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

def project_id
  project.id
end

#sourceObject


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

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: 1.day.from_now),
    global_id: global_id,
    sha256: deployment.file_sha256,
    file_size: deployment.size,
    file_count: deployment.file_count
  }
end