Class: DataMapper::Validations::ConfirmationValidator

Inherits:
GenericValidator show all
Defined in:
lib/dm-validations/validators/confirmation_validator.rb

Overview

Author:

  • Guy van den Berg

Since:

  • 0.9

Instance Attribute Summary

Attributes inherited from GenericValidator

#field_name, #humanized_field_name, #if_clause, #options, #unless_clause

Instance Method Summary collapse

Methods inherited from GenericValidator

#==, #add_error, #evaluate_conditional_clause, #execute?, #inspect, #optional?, #set_optional_by_default

Constructor Details

#initialize(field_name, options = {}) ⇒ ConfirmationValidator

Returns a new instance of ConfirmationValidator.

Since:

  • 0.9



8
9
10
11
12
13
14
15
16
# File 'lib/dm-validations/validators/confirmation_validator.rb', line 8

def initialize(field_name, options = {})
  super

  set_optional_by_default

  @confirm_field_name = (
    options[:confirm] || "#{field_name}_confirmation"
  ).to_sym
end

Instance Method Details

#call(target) ⇒ Object

Since:

  • 0.9



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dm-validations/validators/confirmation_validator.rb', line 18

def call(target)
  return true if valid?(target)

  error_message = (
    @options[:message] || ValidationErrors.default_error_message(
      :confirmation, field_name
    )
  )
  add_error(target, error_message, field_name)

  false
end