debian-mirror-gitlab/app/models/concerns/packages/debian/architecture.rb

33 lines
1.1 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
module Packages
module Debian
module Architecture
extend ActiveSupport::Concern
included do
belongs_to :distribution, class_name: "Packages::Debian::#{container_type.capitalize}Distribution", inverse_of: :architectures
2021-03-11 19:13:27 +05:30
# files must be destroyed by ruby code in order to properly remove carrierwave uploads
has_many :files,
class_name: "Packages::Debian::#{container_type.capitalize}ComponentFile",
foreign_key: :architecture_id,
inverse_of: :architecture,
dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
2021-03-08 18:12:59 +05:30
validates :distribution,
presence: true
validates :name,
presence: true,
length: { maximum: 255 },
uniqueness: { scope: %i[distribution_id] },
format: { with: Gitlab::Regex.debian_architecture_regex }
2021-06-08 01:23:25 +05:30
scope :ordered_by_name, -> { order(:name) }
2021-03-08 18:12:59 +05:30
scope :with_distribution, ->(distribution) { where(distribution: distribution) }
scope :with_name, ->(name) { where(name: name) }
end
end
end
end