Class: NotNaughty::ConfirmationValidation

Inherits:
Validation show all
Defined in:
lib/not_naughty/validations/confirmation_validation.rb

Overview

Validates confirmaton of obj’s attribute via :eql? call against the appropiate confirmation attribute.

Unless the validation succeeds an error hash (:attribute => :message) is added to the obj’s instance of Errors.

Options:

:message

see NotNaughty::Errors for details

:if

see NotNaughty::Validation::Condition for details

:unless

see NotNaughty::Validation::Condition for details

Example:

obj = 'abc'
def obj.errors() @errors ||= NotNauthy::Errors.new end
def obj.to_s_confirmation() '123 end

ConfirmationValidation.new({}, :to_s).call obj, :to_s, 'abc'
obj.errors.on(:to_s).any? # => true

Constant Summary

Constants inherited from Validation

Validation::PATTERN

Instance Attribute Summary

Attributes inherited from Validation

#attributes

Instance Method Summary collapse

Methods inherited from Validation

#call_with_conditions, #call_without_conditions, inherited, load, load_paths, new

Constructor Details

#initialize(valid, attributes) ⇒ ConfirmationValidation

:nodoc:



23
24
25
26
27
28
29
30
31
32
# File 'lib/not_naughty/validations/confirmation_validation.rb', line 23

def initialize(valid, attributes) #:nodoc:
  valid[:message] ||= '%s could not be confirmed.'

  if valid[:allow_blank] || valid[:allow_nil]
    valid[:allow] = valid[:allow_blank] ? :blank? : :nil?
    super valid, attributes, &confirmation_block_with_exception(valid)
  else
    super valid, attributes, &confirmation_block(valid)
  end
end