You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
485 B

6 months ago
module Carto
class UsernameProposer
def self.find_unique(candidate_username, offset: 0, max_retries: 99)
suffix = "-#{offset}" if offset > 0
candidate_username_with_suffix = "#{candidate_username}#{suffix}"
if offset < max_retries && Carto::User.exists?(username: candidate_username_with_suffix)
find_unique(candidate_username, offset: offset + 1, max_retries: max_retries)
else
candidate_username_with_suffix
end
end
end
end