Class: ActiveModel::Validations::ConfirmationValidator

Inherits:
EachValidator show all
Defined in:
lib/active_model/validations/confirmation.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from EachValidator

#attributes

Attributes inherited from ActiveModel::Validator

#options

Instance Method Summary collapse

Methods inherited from EachValidator

#check_validity!, #validate

Methods inherited from ActiveModel::Validator

kind, #kind, #validate

Constructor Details

#initialize(options) ⇒ ConfirmationValidator

Returns a new instance of ConfirmationValidator.



6
7
8
9
# File 'lib/active_model/validations/confirmation.rb', line 6

def initialize(options)
  super({ case_sensitive: true }.merge!(options))
  setup!(options[:class])
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/active_model/validations/confirmation.rb', line 11

def validate_each(record, attribute, value)
  unless (confirmed = record.public_send("#{attribute}_confirmation")).nil?
    unless confirmation_value_equal?(record, attribute, value, confirmed)
      human_attribute_name = record.class.human_attribute_name(attribute)
      record.errors.add(:"#{attribute}_confirmation", :confirmation, **options.except(:case_sensitive).merge!(attribute: human_attribute_name))
    end
  end
end