nonatomic_internal_id.rb 466 Bytes
Newer Older
1
module NonatomicInternalId
2
3
4
5
6
7
8
9
  extend ActiveSupport::Concern

  included do
    validate :set_iid, on: :create
    validates :iid, presence: true, numericality: true
  end

  def set_iid
10
    if iid.blank?
Felipe Artur's avatar
Felipe Artur committed
11
      parent = project || group
12
      records = parent.public_send(self.class.name.tableize) # rubocop:disable GitlabSecurity/PublicSend
13
      max_iid = records.maximum(:iid)
14

15
16
      self.iid = max_iid.to_i + 1
    end
17
18
19
20
21
22
  end

  def to_param
    iid.to_s
  end
end