Class: Packages::Package

Inherits:
ApplicationRecord show all
Includes:
Gitlab::SQL::Pattern, 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 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, without_order

Class Method Details

.by_file_name_and_sha256(file_name, sha256) ⇒ Object


117
118
119
120
# File 'app/models/packages/package.rb', line 117

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


111
112
113
114
115
# File 'app/models/packages/package.rb', line 111

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

.for_projects(projects) ⇒ Object


101
102
103
104
105
# File 'app/models/packages/package.rb', line 101

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

  where(project_id: projects)
end

.only_maven_packages_with_path(path) ⇒ Object


107
108
109
# File 'app/models/packages/package.rb', line 107

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

.pluck_namesObject


122
123
124
# File 'app/models/packages/package.rb', line 122

def self.pluck_names
  pluck(:name)
end

.pluck_versionsObject


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

def self.pluck_versions
  pluck(:version)
end

.sort_by_attribute(method) ⇒ Object


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/models/packages/package.rb', line 130

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

#pipelineObject


159
160
161
# File 'app/models/packages/package.rb', line 159

def pipeline
  build_info&.pipeline
end

#tag_namesObject


163
164
165
# File 'app/models/packages/package.rb', line 163

def tag_names
  tags.pluck(:name)
end

#versionsObject


149
150
151
152
153
154
155
156
157
# File 'app/models/packages/package.rb', line 149

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