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

metadatum.rb « nuget « packages « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08276f87568cdf9899db1fb79d9f1d2b9d8a92bb (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
# frozen_string_literal: true

class Packages::Nuget::Metadatum < ApplicationRecord
  MAX_AUTHORS_LENGTH = 255
  MAX_DESCRIPTION_LENGTH = 4000

  belongs_to :package, -> { where(package_type: :nuget) }, inverse_of: :nuget_metadatum

  validates :package, presence: true
  validates :license_url, public_url: { allow_blank: true }
  validates :project_url, public_url: { allow_blank: true }
  validates :icon_url, public_url: { allow_blank: true }
  validates :authors, presence: true, length: { maximum: MAX_AUTHORS_LENGTH }
  validates :description, presence: true, length: { maximum: MAX_DESCRIPTION_LENGTH }

  validate :ensure_nuget_package_type

  private

  def ensure_nuget_package_type
    return if package&.nuget?

    errors.add(:base, _('Package type must be NuGet'))
  end
end