Class: Warden::Proxy::Errors
- Inherits:
-
Object
- Object
- Warden::Proxy::Errors
- Includes:
- Enumerable
- Defined in:
- lib/warden/errors.rb
Overview
Lifted from DataMapper’s dm-validations plugin :)
Instance Method Summary collapse
-
#add(field_name, message) ⇒ Object
Add a authentication error.
-
#clear! ⇒ Object
Clear existing authentication errors.
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#full_messages ⇒ Object
Collect all errors into a single list.
- #method_missing(meth, *args, &block) ⇒ Object
-
#on(field_name) ⇒ Object
Return authentication errors for a particular field_name.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
56 57 58 |
# File 'lib/warden/errors.rb', line 56 def method_missing(meth, *args, &block) errors.send(meth, *args, &block) end |
Instance Method Details
#add(field_name, message) ⇒ Object
Add a authentication error. Use the field_name :general if the errors does not apply to a specific field of the Resource.
26 27 28 |
# File 'lib/warden/errors.rb', line 26 def add(field_name, ) (errors[field_name] ||= []) << end |
#clear! ⇒ Object
Clear existing authentication errors.
17 18 19 |
# File 'lib/warden/errors.rb', line 17 def clear! errors.clear end |
#each ⇒ Object
45 46 47 48 49 50 |
# File 'lib/warden/errors.rb', line 45 def each errors.map.each do |k,v| next if blank?(v) yield(v) end end |
#empty? ⇒ Boolean
52 53 54 |
# File 'lib/warden/errors.rb', line 52 def empty? entries.empty? end |
#full_messages ⇒ Object
Collect all errors into a single list.
31 32 33 34 35 |
# File 'lib/warden/errors.rb', line 31 def errors.inject([]) do |list,pair| list += pair.last end end |
#on(field_name) ⇒ Object
Return authentication errors for a particular field_name.
40 41 42 43 |
# File 'lib/warden/errors.rb', line 40 def on(field_name) errors_for_field = errors[field_name] blank?(errors_for_field) ? nil : errors_for_field end |