Class: Toolchain::Validations::Validators::Confirmation

Inherits:
Base
  • Object
show all
Defined in:
lib/toolchain/validations/validators/confirmation.rb

Overview

Validates the confirmation of an attribute. In the example both ‘password` and `password_confirmation` attributes must match. One or more `nil` values will result in the validation error being triggered as well.

Examples:

class User::Creator
  validates :password, confirmation: {
    message: "doesn't match confirmation"
  }
end

Instance Attribute Summary

Attributes inherited from Base

#data, #errors, #key_path, #message, #object

Instance Method Summary collapse

Methods inherited from Base

#initialize, #value

Constructor Details

This class inherits a constructor from Toolchain::Validations::Validators::Base

Instance Method Details

#validateObject



17
18
19
20
21
# File 'lib/toolchain/validations/validators/confirmation.rb', line 17

def validate
  if no_match?
    errors.add(key_path, message || "doesn't match confirmation")
  end
end