summaryrefslogtreecommitdiff
path: root/app/models/concerns/atomic_internal_id.rb
blob: 3cc9ce7f03fba8df94083bd567b7544cbaa2e9ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module AtomicInternalId
  extend ActiveSupport::Concern

  included do
    before_validation(on: :create) do
      set_iid
    end

    validates :iid, presence: true, numericality: true
  end

  def set_iid
    self.iid = InternalId.generate_next(self.project, :issues) if iid.blank?
  end

  def to_param
    iid.to_s
  end
end