Module: UniqueIdentifier::InstanceMethods

Defined in:
lib/unique_identifier.rb

Instance Method Summary collapse

Instance Method Details

#generate_unique_idObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/unique_identifier.rb', line 19

def generate_unique_id
  return if self.send(self.class::FIELD)
  identifier = loop do
    random = self.class::BLOCK.call
    unless self.class.base_class.exists?(self.class::FIELD => random)
      break random
    end
  end
  self.send "#{self.class::FIELD}=", identifier
end