Welcome to mirror list, hosted at ThFree Co, Russian Federation.

metadatum.rb « conan « packages « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7ec2641177abdca27910ba4f29a7b053bb32ff42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

class Packages::Conan::Metadatum < ApplicationRecord
  belongs_to :package, -> { where(package_type: :conan) }, inverse_of: :conan_metadatum

  validates :package, presence: true

  validates :package_username,
    presence: true,
    format: { with: Gitlab::Regex.conan_recipe_component_regex }

  validates :package_channel,
    presence: true,
    format: { with: Gitlab::Regex.conan_recipe_component_regex }

  validate :conan_package_type

  def recipe
    "#{package.name}/#{package.version}@#{package_username}/#{package_channel}"
  end

  def recipe_path
    recipe.tr('@', '/')
  end

  def self.package_username_from(full_path:)
    full_path.tr('/', '+')
  end

  def self.full_path_from(package_username:)
    package_username.tr('+', '/')
  end

  private

  def conan_package_type
    unless package&.conan?
      errors.add(:base, _('Package type must be Conan'))
    end
  end
end