Class: DataMapper::ValidationErrors
- Inherits:
-
Object
- Object
- DataMapper::ValidationErrors
- Defined in:
- lib/data_mapper/validations/validation_errors.rb
Instance Method Summary collapse
-
#add(attribute, message) ⇒ Object
Add a validation error.
-
#clear! ⇒ Object
Clear existing validation errors.
-
#empty? ⇒ Boolean
Are any errors present?.
-
#full_messages ⇒ Object
Collect all errors into a single list.
-
#initialize ⇒ ValidationErrors
constructor
A new instance of ValidationErrors.
Constructor Details
#initialize ⇒ ValidationErrors
Returns a new instance of ValidationErrors.
5 6 7 |
# File 'lib/data_mapper/validations/validation_errors.rb', line 5 def initialize @errors = Hash.new { |h,k| h[k.to_sym] = [] } end |
Instance Method Details
#add(attribute, message) ⇒ Object
Add a validation error. Use the attribute :general if the error doesn’t apply to a specific attribute.
16 17 18 |
# File 'lib/data_mapper/validations/validation_errors.rb', line 16 def add(attribute, ) @errors[attribute] << end |
#clear! ⇒ Object
Clear existing validation errors.
10 11 12 |
# File 'lib/data_mapper/validations/validation_errors.rb', line 10 def clear! @errors.clear end |
#empty? ⇒ Boolean
Are any errors present?
28 29 30 |
# File 'lib/data_mapper/validations/validation_errors.rb', line 28 def empty? @errors.empty? end |
#full_messages ⇒ Object
Collect all errors into a single list.
21 22 23 24 25 |
# File 'lib/data_mapper/validations/validation_errors.rb', line 21 def @errors.inject([]) do |list,pair| list += pair.last end end |