@author Guy van den Berg @since 0.9
# File lib/dm-validations/validation_errors.rb, line 40 40: def self.default_error_message(key, field, *values) 41: field = DataMapper::Inflector.humanize(field) 42: @@default_error_messages[key] % [field, *values].flatten 43: end
Holds a hash with all the default error messages that can be replaced by your own copy or localizations.
# File lib/dm-validations/validation_errors.rb, line 36 36: def self.default_error_messages=(default_error_messages) 37: @@default_error_messages = default_error_messages 38: end
# File lib/dm-validations/validation_errors.rb, line 123 123: def [](property_name) 124: if (property_errors = errors[property_name.to_sym]) 125: property_errors 126: end 127: end
Add a validation error. Use the field_name :general if the errors does not apply to a specific field of the Resource.
@param [Symbol] field_name
The name of the field that caused the error
@param [String] message
The message to add
# File lib/dm-validations/validation_errors.rb, line 65 65: def add(field_name, message) 66: # see 6abe8fff in extlib, but don't enforce 67: # it unless Edge version is installed 68: if message.respond_to?(:try_call) 69: # DM resource 70: message = if (resource.respond_to?(:model) && 71: resource.model.respond_to?(:properties)) 72: message.try_call( 73: resource, 74: resource.model.properties[field_name] 75: ) 76: else 77: # pure Ruby object 78: message.try_call(resource) 79: end 80: end 81: 82: (errors[field_name] ||= []) << message 83: end
Clear existing validation errors.
# File lib/dm-validations/validation_errors.rb, line 53 53: def clear! 54: errors.clear 55: end
# File lib/dm-validations/validation_errors.rb, line 105 105: def each 106: errors.each_value do |v| 107: yield(v) unless DataMapper::Ext.blank?(v) 108: end 109: end
# File lib/dm-validations/validation_errors.rb, line 111 111: def empty? 112: @errors.all? { |property_name, errors| errors.empty? } 113: end
Collect all errors into a single list.
# File lib/dm-validations/validation_errors.rb, line 86 86: def full_messages 87: errors.inject([]) do |list, pair| 88: list += pair.last 89: end 90: end
# File lib/dm-validations/validation_errors.rb, line 115 115: def method_missing(meth, *args, &block) 116: errors.send(meth, *args, &block) 117: end
Return validation errors for a particular field_name.
@param [Symbol] field_name
The name of the field you want an error for.
@return [Array
Array of validation errors or empty array, if there are no errors on given field
# File lib/dm-validations/validation_errors.rb, line 100 100: def on(field_name) 101: errors_for_field = errors[field_name] 102: DataMapper::Ext.blank?(errors_for_field) ? nil : errors_for_field.uniq 103: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.