Class: SpreeCmCommissioner::Users::Username::Generate
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Users::Username::Generate
- Defined in:
- app/services/spree_cm_commissioner/users/username/generate.rb
Constant Summary collapse
- SAFE_USERNAME_PREFIXES =
Travel/Social Username Prefixes - See github.com/channainfo/commissioner/pull/3389 Format: NamePrefixNumber (e.g., TheaTraveler1) or PrefixNumber (e.g., Traveler1)
%w[ Traveler Rider Explorer Voyager Passenger Journey Buddy Mate Friend Crew ].freeze
Class Method Summary collapse
-
.call(user:, max_attempts: 10) ⇒ String
Generate unique username for a user with collision safety.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(user, max_attempts: 10) ⇒ Generate
constructor
A new instance of Generate.
Constructor Details
#initialize(user, max_attempts: 10) ⇒ Generate
Returns a new instance of Generate.
22 23 24 25 |
# File 'app/services/spree_cm_commissioner/users/username/generate.rb', line 22 def initialize(user, max_attempts: 10) @user = user @max_attempts = max_attempts end |
Class Method Details
.call(user:, max_attempts: 10) ⇒ String
Generate unique username for a user with collision safety
18 19 20 |
# File 'app/services/spree_cm_commissioner/users/username/generate.rb', line 18 def self.call(user:, max_attempts: 10) new(user, max_attempts: max_attempts).call end |
Instance Method Details
#call ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'app/services/spree_cm_commissioner/users/username/generate.rb', line 27 def call @max_attempts.times do username = generate_clean_username return username unless Spree::User.exists?(login: username) end # Last resort: use extended number range generate_clean_username(number_range: 10_000..99_999) end |