@author Guy van den Berg @since 0.9
# File lib/dm-validations/validators/format_validator.rb, line 26 26: def call(target) 27: return true if valid?(target) 28: 29: value = target.validation_property_value(field_name) 30: 31: error_message = ( 32: @options[:message] || ValidationErrors.default_error_message( 33: :invalid, field_name 34: ) 35: ) 36: 37: add_error( 38: target, 39: error_message.try_call(humanized_field_name, value), 40: field_name 41: ) 42: false 43: end
# File lib/dm-validations/validators/format_validator.rb, line 47 47: def valid?(target) 48: value = target.validation_property_value(field_name) 49: return true if optional?(value) 50: 51: validation = @options[:as] || @options[:with] 52: 53: if validation.is_a?(Symbol) && !FORMATS.has_key?(validation) 54: raise("No such predefined format '#{validation}'") 55: end 56: 57: validator = if validation.is_a?(Symbol) 58: FORMATS[validation][0] 59: else 60: validation 61: end 62: 63: case validator 64: when Proc then validator.call(value) 65: when Regexp then value ? value.to_s =~ validator : false 66: else 67: raise(UnknownValidationFormat, "Can't determine how to validate #{target.class}##{field_name} with #{validator.inspect}") 68: end 69: rescue Encoding::CompatibilityError 70: # This is to work around a bug in jruby - see formats/email.rb 71: false 72: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.