class Warden::Proxy::Errors
Lifted from DataMapper's dm-validations plugin :) @author Guy van den Berg @since DM 0.9
Public Instance Methods
add(field_name, message)
click to toggle source
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/warden/errors.rb, line 22 def add(field_name, message) (errors[field_name] ||= []) << message end
clear!()
click to toggle source
Clear existing authentication errors.
# File lib/warden/errors.rb, line 13 def clear! errors.clear end
each() { |v| ... }
click to toggle source
# File lib/warden/errors.rb, line 41 def each errors.map.each do |k,v| next if blank?(v) yield(v) end end
empty?()
click to toggle source
# File lib/warden/errors.rb, line 48 def empty? entries.empty? end
full_messages()
click to toggle source
Collect all errors into a single list.
# File lib/warden/errors.rb, line 27 def full_messages errors.inject([]) do |list,pair| list += pair.last end end
method_missing(meth, *args, &block)
click to toggle source
# File lib/warden/errors.rb, line 52 def method_missing(meth, *args, &block) errors.send(meth, *args, &block) end
on(field_name)
click to toggle source
Return authentication errors for a particular field_name.
@param <Symbol> field_name the name of the field you want an error for
# File lib/warden/errors.rb, line 36 def on(field_name) errors_for_field = errors[field_name] blank?(errors_for_field) ? nil : errors_for_field end
Private Instance Methods
blank?(thing)
click to toggle source
# File lib/warden/errors.rb, line 61 def blank?(thing) thing.nil? || thing == "" || (thing.respond_to?(:empty?) && thing.empty?) end
errors()
click to toggle source
# File lib/warden/errors.rb, line 57 def errors @errors ||= {} end