Initial commit
This commit is contained in:
17
app/models/concerns/tid_identifiable.rb
Normal file
17
app/models/concerns/tid_identifiable.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
module TIDIdentifiable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
validates :tid, presence: true, uniqueness: { case_sensitive: false }
|
||||
|
||||
before_validation do
|
||||
next unless tid.blank?
|
||||
begin
|
||||
self.tid = "TID#{SecureRandom.hex(5).upcase}"
|
||||
end while self.class.where(tid: tid).any?
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user