debian-mirror-gitlab/app/models/repository_language.rb

21 lines
686 B
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class RepositoryLanguage < ApplicationRecord
2021-03-11 19:13:27 +05:30
extend SuppressCompositePrimaryKeyWarning
2018-11-18 11:00:15 +05:30
belongs_to :project
belongs_to :programming_language
2020-06-23 00:09:42 +05:30
default_scope { includes(:programming_language) } # rubocop:disable Cop/DefaultScope
2018-11-18 11:00:15 +05:30
2022-06-21 17:19:12 +05:30
scope :with_programming_language, ->(*names) do
joins(:programming_language).merge(ProgrammingLanguage.with_name_case_insensitive(*names))
2021-09-30 23:02:18 +05:30
end
2018-11-18 11:00:15 +05:30
validates :project, presence: true
2019-12-21 20:55:43 +05:30
validates :share, inclusion: { in: 0..100, message: "The share of a language is between 0 and 100" }
2018-11-18 11:00:15 +05:30
validates :programming_language, uniqueness: { scope: :project_id }
delegate :name, :color, to: :programming_language
end