@author Guy van den Berg @since 0.9
# File lib/dm-validations/validators/required_field_validator.rb, line 7 7: def call(target) 8: value = target.validation_property_value(field_name) 9: property = get_resource_property(target, field_name) 10: return true if present?(value, property) 11: 12: error_message = @options[:message] || default_error(property) 13: add_error(target, error_message, field_name) 14: 15: false 16: end
Is the property a boolean property?
@return [Boolean]
Returns true for Boolean, ParanoidBoolean, TrueClass and other properties. Returns false for other property types or for non-properties.
# File lib/dm-validations/validators/required_field_validator.rb, line 38 38: def boolean_type?(property) 39: property ? property.primitive == TrueClass : false 40: end
# File lib/dm-validations/validators/required_field_validator.rb, line 27 27: def default_error(property) 28: actual = boolean_type?(property) ? :nil : :blank 29: ValidationErrors.default_error_message(actual, field_name) 30: end
Boolean property types are considered present if non-nil. Other property types are considered present if non-blank. Non-properties are considered present if non-blank.
# File lib/dm-validations/validators/required_field_validator.rb, line 23 23: def present?(value, property) 24: boolean_type?(property) ? !value.nil? : !DataMapper::Ext.blank?(value) 25: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.