Class: Packages::Package

Inherits:
ApplicationRecord show all
Includes:
Gitlab::SQL::Pattern, Gitlab::Utils::StrongMemoize, Sortable, UsageStatistics
Defined in:
app/models/packages/package.rb

Constant Summary

Constants included from Gitlab::SQL::Pattern

Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_WORD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, where_exists, with_fast_statement_timeout, without_order

Class Method Details

.by_file_name_and_sha256(file_name, sha256) ⇒ Object


125
126
127
128
# File 'app/models/packages/package.rb', line 125

def self.by_file_name_and_sha256(file_name, sha256)
  joins(:package_files)
    .where(packages_package_files: { file_name: file_name, file_sha256: sha256 }).last!
end

.by_name_and_file_name(name, file_name) ⇒ Object


119
120
121
122
123
# File 'app/models/packages/package.rb', line 119

def self.by_name_and_file_name(name, file_name)
  with_name(name)
    .joins(:package_files)
    .where(packages_package_files: { file_name: file_name }).last!
end

.by_name_and_version!(name, version) ⇒ Object


130
131
132
# File 'app/models/packages/package.rb', line 130

def self.by_name_and_version!(name, version)
  find_by!(name: name, version: version)
end

.for_projects(projects) ⇒ Object


109
110
111
112
113
# File 'app/models/packages/package.rb', line 109

def self.for_projects(projects)
  return none unless projects.any?

  where(project_id: projects)
end

.only_maven_packages_with_path(path) ⇒ Object


115
116
117
# File 'app/models/packages/package.rb', line 115

def self.only_maven_packages_with_path(path)
  joins(:maven_metadatum).where(packages_maven_metadata: { path: path })
end

.pluck_namesObject


134
135
136
# File 'app/models/packages/package.rb', line 134

def self.pluck_names
  pluck(:name)
end

.pluck_versionsObject


138
139
140
# File 'app/models/packages/package.rb', line 138

def self.pluck_versions
  pluck(:version)
end

.sort_by_attribute(method) ⇒ Object


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/models/packages/package.rb', line 142

def self.sort_by_attribute(method)
  case method.to_s
  when 'created_asc' then order_created
  when 'created_at_asc' then order_created
  when 'name_asc' then order_name
  when 'name_desc' then order_name_desc
  when 'version_asc' then order_version
  when 'version_desc' then order_version_desc
  when 'type_asc' then order_type
  when 'type_desc' then order_type_desc
  when 'project_name_asc' then order_project_name
  when 'project_name_desc' then order_project_name_desc
  when 'project_path_asc' then order_project_path
  when 'project_path_desc' then order_project_path_desc
  else
    order_created_desc
  end
end

Instance Method Details

#original_build_infoObject

Technical debt: to be removed in gitlab.com/gitlab-org/gitlab/-/issues/281937


172
173
174
175
176
# File 'app/models/packages/package.rb', line 172

def original_build_info
  strong_memoize(:original_build_info) do
    build_infos.first
  end
end

#pipelineObject

Technical debt: to be removed in gitlab.com/gitlab-org/gitlab/-/issues/281937


179
180
181
# File 'app/models/packages/package.rb', line 179

def pipeline
  original_build_info&.pipeline
end

#tag_namesObject


183
184
185
# File 'app/models/packages/package.rb', line 183

def tag_names
  tags.pluck(:name)
end

#versionsObject


161
162
163
164
165
166
167
168
169
# File 'app/models/packages/package.rb', line 161

def versions
  project.packages
         .including_build_info
         .including_tags
         .with_name(name)
         .where.not(version: version)
         .with_package_type(package_type)
         .order(:version)
end