Class: DataMapper::Validate::ValidationErrors
- Includes:
- Enumerable
- Defined in:
- lib/gems/dm-validations-0.9.9/lib/dm-validations/validation_errors.rb
Overview
Instance Method Summary collapse
-
#add(field_name, message) ⇒ Object
Add a validation error.
-
#clear! ⇒ Object
Clear existing validation 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 validation errors for a particular field_name.
Methods included from Enumerable
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
52 53 54 |
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/validation_errors.rb', line 52 def method_missing(meth, *args, &block) errors.send(meth, *args, &block) end |
Instance Method Details
#add(field_name, message) ⇒ Object
Add a validation error. Use the field_name :general if the errors does not apply to a specific field of the Resource.
22 23 24 |
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/validation_errors.rb', line 22 def add(field_name, ) (errors[field_name] ||= []) << end |
#clear! ⇒ Object
Clear existing validation errors.
13 14 15 |
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/validation_errors.rb', line 13 def clear! errors.clear end |
#each ⇒ Object
41 42 43 44 45 46 |
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/validation_errors.rb', line 41 def each errors.map.each do |k,v| next if v.blank? yield(v) end end |
#empty? ⇒ Boolean
48 49 50 |
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/validation_errors.rb', line 48 def empty? entries.empty? end |
#full_messages ⇒ Object
Collect all errors into a single list.
27 28 29 30 31 |
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/validation_errors.rb', line 27 def errors.inject([]) do |list,pair| list += pair.last end end |
#on(field_name) ⇒ Object
Return validation errors for a particular field_name.
36 37 38 39 |
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/validation_errors.rb', line 36 def on(field_name) errors_for_field = errors[field_name] errors_for_field.blank? ? nil : errors_for_field end |