Class: ActiveModel::Validations::ConfirmationValidator

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

Instance Attribute Summary

Attributes inherited from EachValidator

#attributes

Attributes inherited from ActiveModel::Validator

#options

Instance Method Summary collapse

Methods inherited from EachValidator

#check_validity!, #initialize, #validate

Methods inherited from ActiveModel::Validator

#initialize, kind, #kind, #validate

Constructor Details

This class inherits a constructor from ActiveModel::EachValidator

Instance Method Details

#setup(klass) ⇒ Object



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

def setup(klass)
  klass.send(:attr_accessor, *attributes.map do |attribute|
    :"#{attribute}_confirmation" unless klass.method_defined?(:"#{attribute}_confirmation")
  end.compact)
end

#validate_each(record, attribute, value) ⇒ Object



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

def validate_each(record, attribute, value)
  if (confirmed = record.send("#{attribute}_confirmation")) && (value != confirmed)
    record.errors.add(attribute, :confirmation, options)
  end
end