@author Guy van den Berg @since 0.9
# File lib/dm-validations/validators/confirmation_validator.rb, line 8 8: def initialize(field_name, options = {}) 9: super 10: 11: set_optional_by_default 12: 13: @confirm_field_name = ( 14: options[:confirm] || "#{field_name}_confirmation" 15: ).to_sym 16: end
# File lib/dm-validations/validators/confirmation_validator.rb, line 18 18: def call(target) 19: return true if valid?(target) 20: 21: error_message = ( 22: @options[:message] || ValidationErrors.default_error_message( 23: :confirmation, field_name 24: ) 25: ) 26: add_error(target, error_message, field_name) 27: 28: false 29: end
# File lib/dm-validations/validators/confirmation_validator.rb, line 33 33: def valid?(target) 34: value = target.validation_property_value(field_name) 35: return true if optional?(value) 36: 37: if target.model.properties.named?(field_name) 38: return true unless target.attribute_dirty?(field_name) 39: end 40: 41: confirm_value = target.instance_variable_get("@#{@confirm_field_name}") 42: value == confirm_value 43: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.