Class: ActiveModel::Validations::ConfirmationValidator
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
ActiveModel::EachValidator
|
Defined in: | activemodel/lib/active_model/validations/confirmation.rb |
Class Method Summary
- .new(options) ⇒ ConfirmationValidator constructor
::ActiveModel::EachValidator
- Inherited
.new | Returns a new validator instance. |
::ActiveModel::Validator
- Inherited
Instance Attribute Summary
Instance Method Summary
- #validate_each(record, attribute, value)
- #confirmation_value_equal?(record, attribute, value, confirmed) ⇒ Boolean private
- #setup!(klass) private
::ActiveModel::EachValidator
- Inherited
#check_validity! | Hook method that gets called by the initializer allowing verification that the arguments supplied are valid. |
#validate | Performs validation on the supplied record. |
#validate_each | Override this method in subclasses with the validation logic, adding errors to the records #errors array where necessary. |
#prepare_value_for_validation |
::ActiveModel::Validator
- Inherited
Constructor Details
.new(options) ⇒ ConfirmationValidator
# File 'activemodel/lib/active_model/validations/confirmation.rb', line 6
def initialize( ) super({ case_sensitive: true }.merge!( )) setup!( [:class]) end
Instance Method Details
#confirmation_value_equal?(record, attribute, value, confirmed) ⇒ Boolean
(private)
# File 'activemodel/lib/active_model/validations/confirmation.rb', line 31
def confirmation_value_equal?(record, attribute, value, confirmed) if ! [:case_sensitive] && value.is_a?(String) value.casecmp(confirmed) == 0 else value == confirmed end end
#setup!(klass) (private)
[ GitHub ]# File 'activemodel/lib/active_model/validations/confirmation.rb', line 21
def setup!(klass) klass.attr_reader(*attributes.filter_map do |attribute| :"#{attribute}_confirmation" unless klass.method_defined?(:"#{attribute}_confirmation") end) klass.attr_writer(*attributes.filter_map do |attribute| :"#{attribute}_confirmation" unless klass.method_defined?(:"#{attribute}_confirmation=") end) end
#validate_each(record, attribute, value)
[ GitHub ]# File 'activemodel/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, ** .except(:case_sensitive).merge!(attribute: human_attribute_name)) end end end