Class: AWS::Record::ConfirmationValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/aws/record/validators/confirmation.rb

Constant Summary collapse

ACCEPTED_OPTIONS =
[:message, :on, :if, :unless]

Instance Attribute Summary

Attributes inherited from Validator

#attribute_names, #options

Instance Method Summary collapse

Methods inherited from Validator

#initialize, #validate

Constructor Details

This class inherits a constructor from AWS::Record::Validator

Instance Method Details

#messageObject



36
37
38
# File 'lib/aws/record/validators/confirmation.rb', line 36

def message
  options[:message] || "doesn't match confirmation"
end

#setup(record_class) ⇒ Object



24
25
26
27
# File 'lib/aws/record/validators/confirmation.rb', line 24

def setup record_class
  accessors = attribute_names.collect{|m| "#{m}_confirmation" }
  add_accessors(record_class, *accessors)
end

#validate_attribute(record, attribute_name, value) ⇒ Object



29
30
31
32
33
34
# File 'lib/aws/record/validators/confirmation.rb', line 29

def validate_attribute record, attribute_name, value
  confirmation_value = record.send("#{attribute_name}_confirmation")
  unless value == confirmation_value
    record.errors.add(attribute_name, message)
  end
end