Class: PasswordValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/password_validator.rb

Overview

Validates the attribute’s value is an acceptable password

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
# File 'app/validators/password_validator.rb', line 3

def validate_each(record, attribute, value)
  if record.password_changing? && value.to_s.size <= 10
    record.errors[attribute] << (options[:message] || "must be minimum 10 characters long")
  elsif record.password.blank? && !record.password_changing?
    record.errors[attribute] << (options[:message] || "must be set")
  end
end