debian-mirror-gitlab/app/models/concerns/internal_id.rb

23 lines
457 B
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module InternalId
extend ActiveSupport::Concern
included do
validate :set_iid, on: :create
validates :iid, presence: true, numericality: true
end
def set_iid
2016-06-02 11:05:42 +05:30
if iid.blank?
2017-09-10 17:25:29 +05:30
parent = project || group
2018-03-17 18:26:18 +05:30
records = parent.public_send(self.class.name.tableize) # rubocop:disable GitlabSecurity/PublicSend
2016-06-02 11:05:42 +05:30
max_iid = records.maximum(:iid)
self.iid = max_iid.to_i + 1
end
2014-09-02 18:07:02 +05:30
end
def to_param
iid.to_s
end
end