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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
662 B
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
class DescriptionVersion < ApplicationRecord
belongs_to :issue
belongs_to :merge_request
validate :exactly_one_issuable
def self.issuable_attrs
%i(issue merge_request).freeze
end
2019-12-26 22:10:19 +05:30
def issuable
issue || merge_request
end
2019-12-21 20:55:43 +05:30
private
def exactly_one_issuable
issuable_count = self.class.issuable_attrs.count { |attr| self["#{attr}_id"] }
2020-04-08 14:13:33 +05:30
if issuable_count != 1
errors.add(
:base,
_("Exactly one of %{attributes} is required") %
{ attributes: self.class.issuable_attrs.join(', ') }
)
end
2019-12-21 20:55:43 +05:30
end
end
2021-06-08 01:23:25 +05:30
DescriptionVersion.prepend_mod_with('DescriptionVersion')