Class: Volt::Errors
- Inherits:
-
ReactiveHash
- Object
- ReactiveHash
- Volt::Errors
- Defined in:
- lib/volt/models/errors.rb
Instance Method Summary collapse
- #add(field, error) ⇒ Object
-
#merge!(errors) ⇒ Object
Merge another set of errors in.
-
#to_s ⇒ Object
Generate a string version of all of the errors.
Methods inherited from ReactiveHash
#==, #[], #[]=, #blank?, #clear, #delete, #initialize, #inspect, #method_missing, #replace, #to_h
Constructor Details
This class inherits a constructor from Volt::ReactiveHash
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Volt::ReactiveHash
Instance Method Details
#add(field, error) ⇒ Object
5 6 7 8 |
# File 'lib/volt/models/errors.rb', line 5 def add(field, error) field_errors = (self[field] ||= []) field_errors << error unless field_errors.include?(error) end |
#merge!(errors) ⇒ Object
Merge another set of errors in
11 12 13 14 15 16 17 18 19 |
# File 'lib/volt/models/errors.rb', line 11 def merge!(errors) if errors errors.each_pair do |field, | .each do || add(field, ) end end end end |
#to_s ⇒ Object
Generate a string version of all of the errors
22 23 24 25 26 27 28 29 30 |
# File 'lib/volt/models/errors.rb', line 22 def to_s str = [] each_pair do |field, error| str << "#{field} #{error}" end str.join end |