Class: UsernameCheckerService
- Inherits:
-
Object
- Object
- UsernameCheckerService
- Defined in:
- app/services/username_checker_service.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_username(username, email) ⇒ Object
- #check_username_availability(username, email) ⇒ Object
-
#initialize(allow_reserved_username: false) ⇒ UsernameCheckerService
constructor
A new instance of UsernameCheckerService.
- #is_developer?(value) ⇒ Boolean
Constructor Details
#initialize(allow_reserved_username: false) ⇒ UsernameCheckerService
Returns a new instance of UsernameCheckerService.
4 5 6 |
# File 'app/services/username_checker_service.rb', line 4 def initialize(allow_reserved_username: false) @allow_reserved_username = allow_reserved_username end |
Class Method Details
.is_developer?(email) ⇒ Boolean
35 36 37 |
# File 'app/services/username_checker_service.rb', line 35 def self.is_developer?(email) UsernameCheckerService.new.is_developer?(email) end |
Instance Method Details
#check_username(username, email) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'app/services/username_checker_service.rb', line 8 def check_username(username, email) if username && username.length > 0 validator = UsernameValidator.new(username) if !validator.valid_format? { errors: validator.errors } else check_username_availability(username, email) end end end |
#check_username_availability(username, email) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/username_checker_service.rb', line 19 def check_username_availability(username, email) available = User.username_available?(username, email, allow_reserved_username: @allow_reserved_username) if available { available: true, is_developer: is_developer?(email) } else { available: false, suggestion: UserNameSuggester.suggest(username) } end end |
#is_developer?(value) ⇒ Boolean
30 31 32 33 |
# File 'app/services/username_checker_service.rb', line 30 def is_developer?(value) Rails.configuration.respond_to?(:developer_emails) && Rails.configuration.developer_emails.include?(value) end |