Module: Devise::Models::PasswordHasRequiredContent

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise/secure_password/models/password_has_required_content.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

LENGTH_MAX =
255

Instance Method Summary collapse

Instance Method Details

#validate_password_confirmation_contentObject



21
22
23
24
25
# File 'lib/devise/secure_password/models/password_has_required_content.rb', line 21

def validate_password_confirmation_content
  self.password_confirmation ||= ''
  validate_password_content_for(:password_confirmation)
  errors[:password_confirmation].count.zero?
end

#validate_password_contentObject



15
16
17
18
19
# File 'lib/devise/secure_password/models/password_has_required_content.rb', line 15

def validate_password_content
  self.password ||= ''
  validate_password_content_for(:password)
  errors[:password].count.zero?
end

#validate_password_content_for(attr) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/devise/secure_password/models/password_has_required_content.rb', line 27

def validate_password_content_for(attr)
  return unless respond_to?(attr) && !(password_obj = send(attr)).nil?
  ::Support::String::CharacterCounter.new.count(password_obj).each do |type, dict|
    error_string =  case type
                    when :unknown then validate_unknown(dict)
                    else validate_type(type, dict)
                    end
    errors.add(attr, error_string) if error_string.present?
  end
end