Module: Username::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/username/model.rb,
app/models/concerns/username/model/devise.rb
Defined Under Namespace
Modules: ClassMethods, Devise
Instance Method Summary collapse
Instance Method Details
#username_available?(username) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/concerns/username/model.rb', line 30 def username_available? username unless username.nil? valid = true if Username.configuration.global_uniqueness Username.configuration.models.each do |model| if model == self.class.name valid = false if model.constantize.all.where(username: username).where.not(id: id).any? else valid = false if model.constantize.all.where(username: username).any? end end else valid = false if self.class.all.where(username: username).where.not(id: id).any? end valid = false if Username.configuration.forbidden.include?(username) || username.length < Username.configuration.minlength || username.length > Username.configuration.maxlength || username !~ Username.configuration.regex valid else true end end |