Lifted from DataMapper’s dm-validations plugin :) @author Guy van den Berg @since DM 0.9
Return validation errors for a particular field name or an empty array
This method is a necessary requirement for active_model compatibility.
@param [Symbol] field_name the name of the field you want an error for @return [Array<Array<String>>]
array of validation errors or empty array, if there are no errors on given field
# File lib/merb-auth-core/errors.rb, line 43 def [](field_name) errors[field_name] ||= [] end
Add a authentication 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/merb-auth-core/errors.rb, line 25 def add(field_name, message) (errors[field_name] ||= []) << message end
Clear existing authentication errors.
# File lib/merb-auth-core/errors.rb, line 16 def clear! errors.clear end
# File lib/merb-auth-core/errors.rb, line 55 def each errors.map.each do |k,v| next if v.blank? yield(v) end end
# File lib/merb-auth-core/errors.rb, line 62 def empty? entries.empty? end
Collect all errors into a single list.
# File lib/merb-auth-core/errors.rb, line 30 def full_messages errors.inject([]) do |list,pair| list += pair.last end end
# File lib/merb-auth-core/errors.rb, line 66 def method_missing(meth, *args, &block) errors.send(meth, *args, &block) end
Return authentication errors for a particular field_name.
@param <Symbol> field_name the name of the field you want an error for
# File lib/merb-auth-core/errors.rb, line 50 def on(field_name) errors_for_field = errors[field_name] errors_for_field.blank? ? nil : errors_for_field end
Generated with the Darkfish Rdoc Generator 2.